首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何激发这个数据库云功能?

如何激发这个数据库云功能?
EN

Stack Overflow用户
提问于 2020-02-18 12:13:53
回答 1查看 91关注 0票数 0

更新

具有挑战性的数据库功能在部署时工作,但不适用于仿真器。

原始问题

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

启动云函数仿真器时,我会在初始化函数列表中的http函数旁边看到数据库云函数,但是每当对它应该监视的数据库路径(potential-students)进行新的修改时,就不会触发数据库云函数。

下面是我的index.js代码片段

代码语言:javascript
复制
// 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"
    }
  });
});

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

代码语言:javascript
复制
exports.notifyOnPreRegistration = functions.database
  .ref("/potential-students")
  .onWrite((change, context) => {
    console.log("running");
    console.log(change);
    console.log(context);
  });
代码语言:javascript
复制
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文件中看到了这个

代码语言:javascript
复制
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

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

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

EN

回答 1

Stack Overflow用户

发布于 2020-02-18 19:01:48

我知道,每次创建、修改或删除文档时,您都需要启动数据库函数,对吗?如果是这样的话,这应该是可行的:

代码语言:javascript
复制
exports.notifyOnPreRegistration = functions.database
  .ref("/potential-students/{studentId}")
  .onWrite((change, context) => {
    console.log("running");
    console.log(change);
    console.log(context);
  });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60280667

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档