Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么';在firebase云函数模拟器上调用firestore onWrite触发器?_Firebase_Google Cloud Firestore_Google Cloud Functions_Firebase Cli - Fatal编程技术网

为什么';在firebase云函数模拟器上调用firestore onWrite触发器?

为什么';在firebase云函数模拟器上调用firestore onWrite触发器?,firebase,google-cloud-firestore,google-cloud-functions,firebase-cli,Firebase,Google Cloud Firestore,Google Cloud Functions,Firebase Cli,我有一个firestore,里面有一个叫做“聊天”的收藏;我使用firestore emulator插入一个新文档,我希望在my上本地运行index.js时调用onWrite触发器(通过运行firebase emulators:start),但它永远不会调用 我知道仿真器连接到了正确的firestore仿真器,因为我可以读取数据(见下文),所以我无法调用触发器 // My setup: const functions = require('firebase-functions'); const

我有一个firestore,里面有一个叫做“聊天”的收藏;我使用firestore emulator插入一个新文档,我希望在my上本地运行
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") });
//我的设置:
const functions=require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp();
//我们能够正确地获取文档,这至少意味着我的
//云函数模拟器连接到firestore模拟器!
admin.firestore().collection(“chats”).doc(“eApXKLLXA4X6tIJtYpOx”).get()
。然后(doc=>{
如果(文件存在){
console.log(“文档数据:”,doc.data());//{console.log(“写时”)};

尝试将文档选择器从
chats/{chat id}
更改为
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,但似乎不是您的情况。
请参阅:

确保firebase使用了正确的项目,请参阅我已将.firebaserc设置为指向正确的项目。因此,这不应该是一个问题。是的,这样做了,下划线呢?是否也禁止使用“\u”?例如,调用/{friend\u id}有没有一个网站解释了所有禁止使用的字符?我在CloudFireStore函数中的许多文档名中都有下划线,无法触发它们。但是当删除奇怪的嵌套
doc(`${lhs}/{${lhs}Id})
时,我错误地将其设置为
doc(`${lhs}/Id`)
.Pub/sub是触发器的服务。因此,在启动期间或在模拟器ui中,请注意模拟器日志。如果调用Pub/sub模拟器时出错,它将告诉您该模拟器未运行。