在模拟器中 运行 时 Firestore 触发器不起作用

Firestore trigger not working when run in emulator

我是 Firebase 的新手,尝试过以下 this video

代码:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp()
const db = admin.firestore()
exports.onUserCreate = functions.firestore.document('users/{userId}').onCreate(async(snapshot, context) => {
const values = snapshot.data()
await db.collection('logging').add({description: `Email was sent to user with username:${values.username}`}) })

这应该会在创建新集合时创建一个名为 'logging' 的新集合。但是触发器在模拟器中不起作用,它只显示我们创建的集合。

看来我的评论很有帮助,将其作为答案发布以提高知名度。

当您使用 set() 方法创建新文档时,会自动创建一个新集合。

没有单独的创建方法collections. Try adding a document as described in the docs。例如,

await db.collection('logging').doc('journal').set(data);