0

My Firestore database looks like this

enter image description here

For documents I use dynamic IDs. I do not use the user ID in the path, it is stored in the field. The fields have the values user and active.

How can I prevent adding new entries if, for example, the user 37870283 already has an active = true?

Anton Bogomolov
  • 79
  • 3
  • 10

1 Answers1

1

There is no way to ensure the uniqueness of a field value in Firestore security rules. The only ways to ensure uniqueness are:

  1. Use the thing that needs to be unique as the document ID.
  2. Perform all writes from a single, trusted process (like Cloud Functions), and use transactions there.

Also see:

And more from this list

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