问题
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