[英]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. 如何在Firebase云功能中使用Firebase Admin SDK为Firestore文档创建文档推送ID。
I know how to do it in Angular using AngularFire2 我知道如何使用AngularFire2在Angular中进行操作
const bookingId = this.afs.createId();
I need to do this thing in my cloud function. 我需要在我的云功能中执行此操作。
Just call doc() with no arguments on a CollectionReference where you would like the document to live. 只需在CollectionReference上调用不带任何参数的doc() ,即可将文档保存在该位置。 You can then call set() on that returned DocumentReference to create the document. 然后,您可以在返回的DocumentReference上调用set()来创建文档。
If you don't even need to create the document and just want the random ID, use the id property on the DocumentReference. 如果您甚至不需要创建文档而只需要随机ID,请使用DocumentReference上的id属性。
(Realtime Database called these things "push IDs" because you used the push()
method, but they're just called auto generated IDs in Firestore). (实时数据库将这些东西称为“推送ID”,因为您使用了push()
方法,但在Firestore中它们仅被称为自动生成的ID)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.