I am creating an Android application for mobile in which it takes the 'Roll number' from each user. That should be unique for each user. Firebase Firestore doesn't provide the unique constraint for particular field. So how can I add the unique constraint on 'Roll number' field. Is there any security rules?
Asked
Active
Viewed 1,829 times
3
-
what have you tried so far. can you share some code? – Aug 18 '18 at 21:23
-
What is the exact constraint that you want to add? Please responde with @. – Alex Mamo Aug 19 '18 at 08:47
-
Maybe you can find something useful here: [https://stackoverflow.com/questions/47405774/cloud-firestore-enforcing-unique-user-names](https://stackoverflow.com/questions/47405774/cloud-firestore-enforcing-unique-user-names). – Bagghi Daku Apr 11 '20 at 14:57
-
Does this answer your question? [Cloud Firestore: Enforcing Unique User Names](https://stackoverflow.com/questions/47405774/cloud-firestore-enforcing-unique-user-names) – Bagghi Daku Apr 11 '20 at 14:58
1 Answers
1
Not out of the box but you can achieve that creating a separate collection to index the unique field and adding a constraint in your security rules.
Checkout this answer which does the trick by using batched writes (which I think is more robust) and this one which use triggers to update the index.

Pedro Andrade
- 4,556
- 1
- 25
- 24