我如何在firebase函数上获取父文档的ID
详细信息收集中有
doc
文档,它是{id}
文档的孩子,col> col
collection中。
我要做的是,当用户更改col/{id}/defot/doc
中的字段时,我想在col/{id}
中更新字段。
exports.onChanged = functions.firestore
.document('col/{id}/details/doc')
.onWrite((change, context) => {
.....
但是,我不知道如何在JavaScript中获取{ID}
。
是否可以将ID
作为字符串获取?
There is doc
document in details
collection, and it is child of {id}
document in col
collection.
What I want to do is, when user changes fields in col/{id}/details/doc
, I wanna update fields in col/{id}
.
exports.onChanged = functions.firestore
.document('col/{id}/details/doc')
.onWrite((change, context) => {
.....
However, I don't know how to get {id}
in JavaScript.
Is there way to get id
as String?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
上下文目的以获取路径中所有通配符的值,如下所示:
You can use the
context
object to get values of all wildcards in your path as shown below:您可以通过调用.parent方法来接收文档的
{id}
。在您的情况下,这可能是两个父母,因为第一位父母是收藏品。因此,要访问文档的{id}将是:
希望它能有所帮助
You might be able to receive the
{id}
of the document by calling the .parent method. In your case it might be two parents up, since the first parent is the collection.So to access the {id} of the document would be:
Hope it helped