【发布时间】:2020-09-19 11:12:14
【问题描述】:
我有一个名为“chats”的集合;我使用 firestore 模拟器插入一个新文档,并且我希望在我的 firebase cloud functions emulator 本地运行 index.js 时调用 onWrite 触发器(通过运行 firebase emulators:start),但它永远不会。
我知道模拟器已连接到正确的 Firestore 模拟器,因为我可以读取数据(见下文),但我无法调用触发器。
// My setup:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// We are able to fetch a document correctly, meaning at least my
// cloud functions emulator is hooked up to the firestore emulator!
admin.firestore().collection("chats").doc("eApXKLLXA4X6tIJtYpOx").get()
.then(doc => {
if (doc.exists) {
console.log("Document data:", doc.data()); // <- this works!!
} else {
throw new Error("No sender document!");
}
})
// This never gets called when I insert a new document through the emulator UI!
exports.myFunction = functions.firestore
.document('chats/{chat-id}')
.onWrite((change, context) => { console.log("on write") });
【问题讨论】:
-
确保firebase使用正确的项目,见Firestore triggers of cloud functions in emulator are ignored
-
我已将 .firebaserc 设置为指向正确的项目。所以这应该不是问题??????♂️
标签: firebase google-cloud-firestore google-cloud-functions firebase-cli