Could a unique ID be a duplicate if I generate an ID from a different path? like:
const id1 = firestore.collection("chat").doc().id;
const id2 = firestore.collection("profile").doc().id;
Is there any chance id1
and id2
could duplicate?
Could a unique ID be a duplicate if I generate an ID from a different path? like:
const id1 = firestore.collection("chat").doc().id;
const id2 = firestore.collection("profile").doc().id;
Is there any chance id1
and id2
could duplicate?
Is there any chance id1 and id2 could duplicate?
The collision of IDs in the case of Firestore is incredibly unlikely and you can/should consider they'll be completely unique. That's what they were designed for. So you don't have to worry about it.
Keep in mind that, the built-in generator for unique IDs which is used in Firestore when you call the CollectionReference#add() method or CollectionReference#document() method without passing any arguments, generates random and highly unpredictable ids, which prevents hitting certain hotspots in the backend infrastructure.
If you're interested in how exactly the document IDs are generated, please check @FrankvanPuffelen's answer from the following post:
Does a unique ID could duplicate if I generate an ID from a different path?
No. Each time you call .doc().id
, a new random document ID is generated.