【发布时间】:2020-07-08 05:06:53
【问题描述】:
我收集了大约 30 条记录 todos,其中几乎 25 条包含单词 work。现在,当我尝试使用 array-contains 时,它不会返回任何内容。
这是我的查询代码:
firebase.firestore().collection("todos")
.where('Workdesc', 'array-contains', 'work')
.get()
.then(querySnapshot => {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " ===> ", doc.data());
});
});
这是我的 Firestore 屏幕截图:
查询似乎按照文档,但为什么它没有返回任何内容?
【问题讨论】:
-
array-contains仅用于数组,它不会在字符串中搜索字符串 -
如果我想在一个字符串中搜索一个单词,那我该怎么做呢?
-
在 Firestore 上不存在在字符串中搜索字符串,因此您需要为此使用另一个/额外的解决方案。有关示例,请参阅此处的 Firebase 文档:firebase.google.com/docs/firestore/solutions/search
-
您的意思是不可能在出现“工作”字样的地方获得结果?没办法?
-
另请参阅stackoverflow.com/questions/46568142/…(阅读所有热门答案,而不仅仅是接受的答案)以及更多内容:google.com/search?q=firestore+query+text+contains。
标签: firebase google-cloud-firestore