简体   繁体   English

如何在Firebase云功能中使用adminSdk为Firestore文档创建文档ID?

[英]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.

相关问题 Firestore - 获取路径未知的 ID 文档 - Firebase Cloud Functions - Firestore - Get document with ID whose path is unknown - Firebase Cloud Functions 如何在使用函数接收集合的创建事件时更新/插入云 Firestore 中的其他文档 - How to update/insert an other document in cloud firestore on receiving a create event for a collection using functions 仅第一个文档作为响应返回,而不是使用 Firestore 和 Cloud Functions 的多个文档 - Only first document is returned as response instead of multiple documents using Firestore and Cloud Functions 如何使用云功能更新此 Firestore 文档字段? - How to update this firestore document field using cloud functions? 如何从云功能中的 firestore 获取文档 - How to get a document from firestore in cloud functions Firebase云功能/ Firestore - Firebase Cloud Functions / Firestore 如何使用Cloud Functions for Firebase更新Firebase Cloud Firestore数据库中的值 - how to update a value in firebase cloud firestore database using Cloud Functions for Firebase 如何从云功能中移动firestore文档? - How to move a firestore document from cloud functions? 如何使用云功能在 Firestore 中创建新字段? - How to create a new field in firestore using cloud functions? 从 Cloud Functions for Firebase 中的 Firestore 触发器获取用户 ID? - Getting the user id from a Firestore Trigger in Cloud Functions for Firebase?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM