How to create a document push id for firestore document using Firebase Admin SDK in Firebase cloud function.
I know how to do it in Angular using AngularFire2
const bookingId = this.afs.createId();
I need to do this thing in my cloud function.
Set the data of a document within a collection, explicitly specifying a document identifier. Add a new document to a collection. In this case, Cloud Firestore automatically generates the document identifier. Create an empty document with an automatically generated identifier, and assign data to it later.
You cannot have several documents with the same ID in one Collection: a document ID must be unique across a collection.
Correct, it is extremely unlikely, but not guaranteed.
Just call doc() with no arguments on a CollectionReference where you would like the document to live. You can then call set() on that returned DocumentReference to create the document.
If you don't even need to create the document and just want the random ID, use the id property on the DocumentReference.
(Realtime Database called these things "push IDs" because you used the push()
method, but they're just called auto generated IDs in Firestore).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With