Reputation: 4287
I know that I'm able to get the unique ID before it was added like this:
DocumentReference ref = db.collection("my_collection").document();
String myId = ref.getId();
My question is: Is it possible that getting the generated ID before it was added will override other data after it adding it? (because this ID may already be generated...).
I know that the probability of generating the same ID twice is very low, but just for the general knowledge. It doesn't seem to me that there is any communication with the database
while doing this.
Upvotes: 1
Views: 76
Reputation: 138944
There is no chance that two users could generate an ID
with the same exact randomness. The point stands that collisions are incredibly unlikely and you can/should assume they'll be completely unique.
Unlike the Realtime Database push IDs, Cloud Firestore IDs are actually purely random, even there's no time component included. But note, this IDs are generated entirely on the client without consultation with the server.
All that said, as far as i know, no one has ever reported a problem with duplicate IDs.
Upvotes: 1