Firestore数组包含查询未返回结果 [英] Firestore array contains query not returning result
问题描述
我在集合todos
中有大约30条记录,其中几乎25条包含单词work
.现在,当我尝试使用array-contains
时,它不会返回任何内容.
I have around 30 records in collection todos
, almost 25 of them contains the word work
. Now when I am trying to use array-contains
it doesn't return anything.
这是我的查询代码:
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屏幕截图:
Here is my Firestore screenshot:
查询似乎按照文档进行,但是为什么不返回任何内容?
Query seems as per docs, but why is it not returning anything?
推荐答案
您没有得到任何结果,因为数据库中的Workdesc
属性的类型为String,而数组的类型为 not .看到引号了吗?如果需要数组类型的属性,则应采用这种方式.请参见followers
属性,它是一个数组.尝试以相同的方式保存其他属性.
You aren't getting any results, because your Workdesc
property in the database is of type String and not array. See the quotation marks? If you need a property of type array, then you should save that way. See followers
property, is an array. Try to save the other property in the same way.
这篇关于Firestore数组包含查询未返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!