我的数据库架构如下:
"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());
});
不幸的是,这段代码没有记录任何内容。我想念什么?我是云功能的新手,所以如果我错过了重要的事情,请告诉我。
答案 0 :(得分:2)
我需要这样做
export const onWorkAddition = functions.database.ref('/Works/{workId}').onCreate((snapshot, context) => {
console.log(context.params.workId);
});