【问题标题】:How do get this database cloud function to fire?如何让这个数据库云功能启动?
【发布时间】:2020-06-02 11:03:30
【问题描述】:

更新

具有挑战性的数据库功能在部署时有效,但不适用于模拟器

原始问题

我的云功能项目中有几个 http 云功能和一个数据库云功能。 所有 http 云功能都运行良好,但无论我做了多少修复,都不会触发数据库云功能。

当我启动云函数模拟器时,我看到数据库云函数与正在初始化的函数列表中的 http 函数一起,但是每当对数据库路径进行新的修改时,数据库云函数永远不会被触发 (potential-students ) 它应该监控。

这是我的index.js 代码的 sn-ps

// This cloud function works perfectly
exports.status = functions.https.onRequest(async (req, resp) => {
  console.log("Hitting /status with", req.hostname, req.baseUrl, req.path);
  return resp.status(200).send({
    ok: true,
    data: {
      message:
        "connected to HTTP Cloud Function listener"
    }
  });
});

这是我尝试过的不同版本的数据库函数

exports.notifyOnPreRegistration = functions.database
  .ref("/potential-students")
  .onWrite((change, context) => {
    console.log("running");
    console.log(change);
    console.log(context);
  });
exports.notifyOnPreRegistration = functions.database
  .ref("potential-students")
  .onWrite((change, context) => {
    console.log("running");
    console.log(change);
    console.log(context);
  });

每当我尝试访问 localhost:9000/potential-students.json 时,我都会收到 null 作为响应。 我也在我的database.debug.log 文件中看到了这一点

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/path/firebase/emulators/firebase-database-emulator-v4.3.1.jar) to field sun.nio.ch.SelectorImpl.selectedKeys
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
12:38:29.482 [NamespaceSystem-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
12:38:29.627 [main] INFO com.firebase.server.forge.App$ - Listening at localhost:9000

下面是我运行模拟器时的终端图片。如果需要,我很乐意提供任何其他非机密信息。

我的问题是:如何启动这个数据库云功能?

【问题讨论】:

  • 你会推荐在 Github 上提交关于此问题的问题吗?

标签: node.js firebase-realtime-database google-cloud-functions firebase-tools


【解决方案1】:

我明白了,每次创建、修改或删除文档时,您都需要触发数据库函数,对吗?如果是这样,这应该工作:

exports.notifyOnPreRegistration = functions.database
  .ref("/potential-students/{studentId}")
  .onWrite((change, context) => {
    console.log("running");
    console.log(change);
    console.log(context);
  });

【讨论】:

  • 谢谢。我已经尝试过了,但它不起作用:(文档说它会在受监控路径上的更改以及受监控路径中的任何嵌套路径上触发
猜你喜欢
  • 1970-01-01
  • 2018-08-20
  • 1970-01-01
  • 2019-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-21
  • 2012-04-28
相关资源
最近更新 更多