在监听新文档创建的函数中。如何获取该文档的 id
export const createUser = functions.firestore
.document('users/{userId}/messages/{messagesID}')
.onCreate((snap, context) => {
// Get an object representing the document
// e.g. {'name': 'Marie', 'age': 66}
const newValue = snap.data();
// access a particular field as you would any JS property
const name = newValue.name;
// perform desired operations ...
});
我猜它是在 context
参数中。我只是没有时间访问它
最佳答案
请查看 documentation for Firestore triggers ,它解释了如何做你想做的事。请特别注意 using wildcards 部分.
函数定义中花括号中的通配符userId
和messagesID
可以在给定的上下文
中访问。
const userId = context.params.userId;
const messagesID = context.params.messagesID;
您还可以使用 id
property 从其快照中获取文档的 ID :
const id = snap.id;
关于typescript - 如何获取创建的文档云函数的ID Typescript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56210625/