0

I have the following data as shown in the image. I want to make sure that the username field is unique. How can I enforce that? Bear in mind that my document id is already unique and I don't want to use my username as the document ID

enter image description here

Ahmed
  • 1,079
  • 2
  • 13
  • 39

1 Answers1

3

There is no way to enforce unique values of fields in Firestore. The only uniqueness you can guarantee is the document IDs within a collection, so the solution is to create a new collection where the user names are used as document IDs.

This has been discussed a few times before, so I recommend checking out:

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734