为什么不在firebase云功能模拟器上调用firestore onWrite触发器? [英] Why doesn't firestore onWrite trigger get invoked on firebase cloud functions emulator?
问题描述
我有一个壁炉,里面有一个叫做聊天室"的收藏;我使用firestore模拟器插入新文档,并且希望在我在
尝试将文档选择器从聊天/{chat-id}
更改为聊天/{chatId}
.看起来这里-
符号被禁止.如果使用它,在 firebase-debug.log
中会出现以下错误:
[debug] [2020-06-01T12:17:29.924Z] 2020年6月1日,下午com.google.cloud.datastore.emulator.impl.util.WrappedStreamObserver onError信息:操作失败:无效的模式.原因:[69:-]捕获表达式的末尾应为'}'.
另一个原因可能是使用了错误的项目ID,但这似乎不是您的情况.请参阅:模拟器中云功能的Firestore触发器将被忽略
I have a firestore with a collection called "chats"; I use the firestore emulator to insert a new document and I am expecting the onWrite
trigger to get called while I am running index.js
locally on my firebase cloud functions emulator (by running firebase emulators:start
), but it never does.
I know that the emulator is connected to the right firestore emulator since I can read the data (see below), I just can't get the trigger to be invoked.
// 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") });
Try to change the document selector from chats/{chat-id}
to chats/{chatId}
. Looks like -
symbol is forbidden here. If I use it, I get the following error in firebase-debug.log
:
[debug] [2020-06-01T12:17:29.924Z] Jun 01, 2020 3:17:29 PM com.google.cloud.datastore.emulator.impl.util.WrappedStreamObserver onError INFO: operation failed: Invalid pattern. Reason: [69:-] Expected '}' at end of capture expression.
Another reason might be using a wrong project id, but it seems it's not your case. See: Firestore triggers of cloud functions in emulator are ignored
这篇关于为什么不在firebase云功能模拟器上调用firestore onWrite触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!