【问题标题】:Is there any way of knowing if a document has been added to a collection in firebase using firebase functions有没有办法知道文档是否已使用 firebase 函数添加到 firebase 的集合中
【发布时间】:2020-03-25 03:00:07
【问题描述】:
基本上又是一个问题:
假设有一个名为“People”的集合。
Firestore 函数可以检测对特定文档的更改,但是是否知道何时使用 firebase 函数将文档(例如“Person1”)添加到集合中?
如果没有,是否有其他方法可以知道何时添加了文档?
【问题讨论】:
标签:
firebase
google-cloud-platform
google-cloud-firestore
google-cloud-functions
【解决方案1】:
有一个特定的函数类型,只有triggers when a document gets created。从文档中可以看出如何使用它的示例:
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 ...
});