Reputation: 359
I'm building a Flutter app, and I'm trying to get documents in a users collection where 1)the boolean value 'finishedOnboarding' is true, and 2) the id 'userId' does not appear in the array 'stingrays'. My current query looks like this:
Stream<List<User>> getUsers(
String userId,
) {
Query<Object?> query =
userCollection.where('finishedOnboarding', isEqualTo: true).limit(10);
return query
.where('stingrays', whereNotIn: [userId])
.limit(10)
.snapshots()
.map((snap) {
return snap.docs.map((doc) => User.fromSnapshot(doc)).toList();
});
}
Running this, firebase tells me to create a compound index. Using the provided link, it generates the following:
Unfortunately, even with this index, the query does not work. It does not throw an error, and users are filtered based on finishedOnboarding, but I still am returned users where userId can be found in the stingrays array. I'm new to compound indexing so this is new to me. Any ideas on what's up with this query?
Edit:
to give so more detail, heres an example situation. For context, im making a type of dating app, where ideally the stingrays array acts as a sort of memory to check if a user has swiped on that individual. In this case, i loaded the query, and a list of 4 users is returned, all with finishedOnboarding:true, and stingrays[] as empty.
However, after running through all 4 users and reloading the query, it still returns all 4 users, despite the user id now existing in the stingrays[] array.
Upvotes: 0
Views: 534
Reputation: 138989
The whereNotIn
cannot be used to query against a field of type array. A not-in query returns only documents where the given field does not match any of the comparison values that exist in the stingrays
list. So this field should contain a single value and not an array, in order to be able to return results.
Upvotes: 2