更新
具有挑战性的数据库功能在部署时有效,但不能在模拟器中使用
原始问题
在我的云功能项目中,我有几个http云功能和一个数据库云功能。 所有http云功能都运行良好,但是无论我做了很多修复,数据库云功能都不会被触发。
启动云功能仿真器时,在正在初始化的功能列表上,我看到数据库云功能和http函数并列,但是无论何时对数据库路径进行新的修改({{1 }})应该监视。
以下是我的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
下面是我运行模拟器时终端的图片。如果需要,我很乐意提供其他任何非秘密信息。
我的问题是:如何启动该数据库云功能?
答案 0 :(得分:0)
我知道您需要在每次创建,修改或删除文档时都启动数据库功能,对吗?如果是这样,这应该可行:
exports.notifyOnPreRegistration = functions.database
.ref("/potential-students/{studentId}")
.onWrite((change, context) => {
console.log("running");
console.log(change);
console.log(context);
});