更新
具有挑战性的数据库功能在部署时工作,但不适用于仿真器。
原始问题
在我的云函数项目中,我有两个http云函数和一个数据库云函数。所有的http云函数都运行良好,但是无论我做了多少修复,数据库云函数都不会被触发。
启动云函数仿真器时,我会在初始化函数列表中的http函数旁边看到数据库云函数,但是每当对它应该监视的数据库路径(potential-students)进行新的修改时,就不会触发数据库云函数。
下面是我的index.js代码片段
// 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下面是我运行模拟器时终端的图片。如果需要的话,我很乐意提供任何其他非机密信息。

我的问题是:如何才能启动这个数据库云功能?
发布于 2020-02-18 19:01:48
我知道,每次创建、修改或删除文档时,您都需要启动数据库函数,对吗?如果是这样的话,这应该是可行的:
exports.notifyOnPreRegistration = functions.database
.ref("/potential-students/{studentId}")
.onWrite((change, context) => {
console.log("running");
console.log(change);
console.log(context);
});https://stackoverflow.com/questions/60280667
复制相似问题