【发布时间】:2018-03-27 06:23:50
【问题描述】:
如何通过 onCreate() cloud firestore 触发器触发的云函数为新创建的文档添加新属性。 是否可以使用相同的方法在客户端和服务器端(即在 Cloud Functions 中)更新文档?
【问题讨论】:
标签: google-cloud-platform google-cloud-firestore google-cloud-functions
如何通过 onCreate() cloud firestore 触发器触发的云函数为新创建的文档添加新属性。 是否可以使用相同的方法在客户端和服务器端(即在 Cloud Functions 中)更新文档?
【问题讨论】:
标签: google-cloud-platform google-cloud-firestore google-cloud-functions
对于the docs,可以使用event.data.ref进行操作:
exports.addUserProperty = functions.firestore
.document('users/{userId}')
.onCreate(event => {
// Get an object representing the document
// e.g. {'name': 'Marie', 'age': 66}
var data = event.data.data();
// add a new property to the user object, write it to Firestore
return event.data.ref.update({
"born": "Poland"
});
});
【讨论】:
{wildcardId} 的用途。它将捕获该位置的所有更改。