我的数据库架构如下:
"Works" : {
"-LLiIlsIS1XJonGRa8j6" : {
"acceptedDate" : {
},
"answers" : {
},
"category" : "matematyka",
"createDate" : {
},
"creatorID" : "KjxVHwUirhUwHRbBDhMCRoHliMQ2",
"finishDate" : {
},
"firebaseKey" : "-LLiIlsIS1XJonGRa8j6",
"level" : "Liceum",
"number" : 1,
"pointAmount" : 8,
"pointBoost" : 0,
"rated" : 1,
"reported" : false,
"solverID" : "XKUNXPozOsMM3sgQXY2F5iVMAkZ2",
"state" : "Completed",
"taskAmount" : 1,
"workText" : "Czy pierwiastek z liczby parzystej zawsze jest liczba parzysta?"
},
"-LLiKGP3Zq1uX3ugRzSF" : {
"acceptedDate" : {
},
"answers" : {
}
},
"available" : false,
"boostAmount" : 0,
"category" : "matematyka",
"createDate" : {
},
"creatorID" : "KjxVHwUirhUwHRbBDhMCRoHliMQ2",
"finishDate" : {
},
"firebaseKey" : "-LLiKGP3Zq1uX3ugRzSF",
"level" : "Liceum",
"number" : 2,
"pointAmount" : 8,
"pointBoost" : 0,
"rated" : 1,
"reported" : false,
"solverID" : "XKUNXPozOsMM3sgQXY2F5iVMAkZ2",
"state" : "Completed",
"taskAmount" : 1,
"workText" : "Czy pierwiastek z liczby ujemnej zawsze jest liczba ujemna?"
}
因此,我希望每次将新对象推送到“ Works”时都启动云功能。到目前为止,我有以下代码:
export const onWorkAddition = functions.database.ref('Works').onCreate(snap => {
console.log('new work created');
console.log(snap.val());
});
不幸的是,这段代码没有记录任何内容。我想念什么?我是云功能的新手,所以如果我错过了重要的事情,请告诉我。
最佳答案
我需要这样
export const onWorkAddition = functions.database.ref('/Works/{workId}').onCreate((snapshot, context) => {
console.log(context.params.workId);
});
关于javascript - 使用Firebase云功能监听后台的更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52405941/