I am using Firebase for this app. Under each documents of a user, I have this array roles. For normal users, their roles would just be user. For an admin, it would be user and admin. I want to retrieve all of the normal users. However, the problem is that if I'll set it like this:
.collection("users")
.where("roles", "!=", "admin")
this will still show the user with an admin role.
How can I retrieve only those normal users and not the user with an admin role?
CodePudding user response:
This would require an array-does-not-contain operation, which does not exist in Firestore.
You might want to consider storing the roles as a map with boolean values, so that you can query for where("roles.admin", "==", false).
Also see:
- Firestore - Possible to query by array-not-contains?
- FireStore - how to get around array "does-not-contain" queries
- Angular Firestore | how to get array not contain
CodePudding user response:
You can use 'not-in' roles not in admin then you will get normal user
docs: https://firebase.google.com/docs/firestore/query-data/queries

