Firestore array contains query not returning result [duplicate]

半世苍凉 提交于 2020-05-09 17:16:10

问题


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.

Here is my query code:

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());
    });
  });

Here is my Firestore screenshot:

Query seems as per docs, but why is it not returning anything?


回答1:


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.



来源:https://stackoverflow.com/questions/60886354/firestore-array-contains-query-not-returning-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!