我有一个 firestore,里面有一个名为“chats”的集合;我使用 firestore 模拟器插入一个新文档,我期待onWrite
当我跑步时触发被调用index.js
本地在我的firebase云函数模拟器 https://firebase.google.com/docs/functions/beta-v1-diff(通过运行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") });
尝试更改文档选择器chats/{chat-id}
to chats/{chatId}
。好像-
此处禁止使用符号。如果我使用它,我会收到以下错误firebase-debug.log
:
[调试] [2020-06-01T12:17:29.924Z] 2020年6月1日下午3:17:29 com.google.cloud.datastore.emulator.impl.util.WrappedStreamObserver onError
信息:操作失败:模式无效。原因:[69:-] 捕获表达式末尾应有“}”。
另一个原因可能是使用了错误的项目 ID,但似乎这不是你的情况。
看:模拟器中云函数的 Firestore 触发器被忽略 https://github.com/firebase/firebase-tools/issues/2078
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)