【问题标题】:Google Cloud Firestore TriggersGoogle Cloud Firestore 触发器
【发布时间】:2018-03-27 06:23:50
【问题描述】:

如何通过 onCreate() cloud firestore 触发器触发的云函数为新创建的文档添加新属性。 是否可以使用相同的方法在客户端和服务器端(即在 Cloud Functions 中)更新文档?

【问题讨论】:

    标签: google-cloud-platform google-cloud-firestore google-cloud-functions


    【解决方案1】:

    对于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"
        });
    });
    

    【讨论】:

    • 我为文档选择了自动生成的ID。那么如何添加特定文档的路径,因为我不知道文档ID
    • 这就是通配符:{wildcardId} 的用途。它将捕获该位置的所有更改。
    猜你喜欢
    • 2018-03-27
    • 1970-01-01
    • 2021-11-09
    • 2020-04-27
    • 2020-10-15
    • 2021-02-21
    • 1970-01-01
    • 2020-02-04
    • 1970-01-01
    相关资源
    最近更新 更多