Ad

How To Create Document Id For Firestore Documents Using AdminSdk In Firebase Cloud Functions?

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.

Ad

Answer

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).

Ad
source: stackoverflow.com
Ad