Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.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
Javascript 云函数的云Firestore触发器_Javascript_Node.js_Firebase_Google Cloud Firestore_Google Cloud Functions - Fatal编程技术网

Javascript 云函数的云Firestore触发器

Javascript 云函数的云Firestore触发器,javascript,node.js,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Firestore,Google Cloud Functions,我使用Firebase,我想使用Cloud函数的Cloud Firestore触发器。 我制作了一个简单的web应用程序来测试云函数的CloudFireStore触发器 但云功能不起作用 你能给我一些建议吗? 先谢谢你 当我从浏览器中按下下载按钮时,我得到Firestore的响应。 但是,我没有得到函数的响应。 没有控制台。日志的Hello触发器 这是我的目录结构 . ├── firebase.json ├── firestore.indexes.json ├── firestore.ru

我使用Firebase,我想使用Cloud函数的Cloud Firestore触发器。

我制作了一个简单的web应用程序来测试云函数的CloudFireStore触发器

但云功能不起作用

你能给我一些建议吗? 先谢谢你

当我从浏览器中按下下载按钮时,我得到Firestore的响应。

但是,我没有得到函数的响应。 没有控制台。日志的Hello触发器

这是我的目录结构

.
├── firebase.json
├── firestore.indexes.json
├── firestore.rules
├── functions
│   ├── index.js
│   ├── package.json
│   └── package-lock.json
├── public
│   ├── index.html
│   └── scripts
│       └── main.js
└── storage.rules
这是index.js

<!doctype html>
<html lang="ja">
   <body>
      <textarea id="text" class="form-control" name="text" placeholder="ここに英文を入力してください。" maxlength="3000" minlength="1"></textarea>
      <br>
      <div style="text-align:center">
        <input id="download" class="btn btn-primary" type="submit" value="音声をダウンロード">
      </div>

      <script src="/__/firebase/7.14.3/firebase-app.js"></script>
      <script src="/__/firebase/7.14.3/firebase-auth.js"></script>
      <script src="/__/firebase/7.14.3/firebase-storage.js"></script>
      <script src="/__/firebase/7.14.3/firebase-messaging.js"></script>
      <script src="/__/firebase/7.14.3/firebase-firestore.js"></script>
      <script src="/__/firebase/7.14.3/firebase-performance.js"></script>
      <script src="/__/firebase/init.js"></script>

      <script src="scripts/main.js"></script>
   </body>
</html>
index.js

const functions = require('firebase-functions');

exports.myFunction = functions.firestore
  .document('messages/messages')
  .onCreate((change, context) => {
    console.log("Hello Trigger!");
    return 0;   

  });

函数设置为在创建一个名为messages/messages的文档时触发。这意味着,只有在名为messages的集合中创建ID为messages的消息时,它才会起作用。我很确定那不是你想要的。如果要在名为messages的集合中的任何新文档上触发,则需要通配符:

exports.myFunction = functions.firestore
  .document('messages/{id}')
  .onCreate((change, context) => { ... })

我建议查看以了解触发器路径中的通配符。

您的函数设置为在创建名为“确切消息/消息”的文档时触发。这意味着,只有在名为messages的集合中创建ID为messages的消息时,它才会起作用。我很确定那不是你想要的。如果要在名为messages的集合中的任何新文档上触发,则需要通配符:

exports.myFunction = functions.firestore
  .document('messages/{id}')
  .onCreate((change, context) => { ... })

我建议查看以了解触发器路径中的通配符。

在index.html添加云函数脚本中,因为缺少该脚本:

<script src="/__/firebase/7.14.3/firebase-functions.js"></script>

在index.html中添加云函数脚本,因为缺少该脚本:

<script src="/__/firebase/7.14.3/firebase-functions.js"></script>

非常感谢你告诉我我愚蠢的错误!非常感谢你告诉我我愚蠢的错误!我误解了“收藏”和“身份”。现在我得到了你好触发器!非常感谢。我误解了“收集”和“ID”。现在我得到了你好触发器!非常感谢。