Google Cloud Firestore 触发器

Google Cloud Firestore Triggers

如何通过由 onCreate() 云 firestore 触发器触发的云函数为新创建的文档添加新属性。 是否可以使用相同的方法在客户端和服务器端(即在 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"
    });
});