0

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.

enter image description here

How can I retrieve only those normal users and not the user with an admin role?

JS3
  • 1,623
  • 3
  • 23
  • 52

2 Answers2

1

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:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
0

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

Indraraj26
  • 1,726
  • 1
  • 14
  • 29