首页 > 解决方案 > 有没有办法知道文档是否已使用 firebase 函数添加到 firebase 的集合中

问题描述

基本上又是一个问题:

假设有一个名为“People”的集合。

Firestore 函数可以检测对特定文档的更改,但是是否知道何时使用 firebase 函数将文档(例如“Person1”)添加到集合中?

如果没有,是否有其他方法可以了解何时添加文档?

标签: firebasegoogle-cloud-platformgoogle-cloud-firestoregoogle-cloud-functions

解决方案


有一个特定的函数类型,仅在创建文档时触发。从文档中可以看出如何使用它的示例:

exports.createUser = functions.firestore
    .document('users/{userId}')
    .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 ...
    });

推荐阅读