Firestore: Are identifiers unique in a collection or globally?

For the structure of my database, I need to know if the automatically generated identifiers are unique in the Firebase Cloud Firestore in the collection or in the entire database.

Did you know? Or do you know how I can find the answer to this question?

+7
firebase google-cloud-firestore
source share
1 answer

The keys created by calling add() in Firestore are not tied to the collection you are calling add() . Instead, they are random identifiers that are statistically guaranteed to be unique. In the case of Firestore (and Firebase Realtime Database), these keys are created on the client side.

If you're interested, see how the Firestore JavaScript SDK implements logic:

The logic itself is similar to how the Firebase Realtime Database generates its push ids. The main difference is that the automatically generated Firestore keys are not based on the local timestamp, so they cannot be meaningfully used to order documents in a collection.

+14
source share

All Articles