我正在尝试使用Firebase Functions实现触发器,该触发器复制数据库中的某些数据。我想观看的所有添加内容votes/user/vote
,其结构为:
我尝试的代码是:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.duplicateFeedback = functions.database.ref('/votes/{userId}/voteId')
.onWrite(event => {
const userId = event.params.userId;
const voteId = event.data.key();
const vote = event.data.val();
console.log(`New feedback from user ${userId}: { description: "${vote.feedback}", score: ${vote.rating}}`);
return;
});
但是我什至无法触发它。任何线索我的函数有什么问题吗?我敢打赌,这与参考资料有关,但我无法弄清楚到底是什么。
现在,该功能由写入以下内容触发
exports.duplicateFeedback = functions.database.ref('/votes/{userId}/voteId')
这将由类似以下内容的事件触发:
votes: {
00000_josemi_foo: {
voteId: {
// data
}
}
}
但是voteId
,您不是要寻找child ,而是要寻找的任何子项{userId}
,例如-33
,因此您需要使用通配符:
exports.duplicateFeedback = functions.database.ref('/votes/{userId}/{voteId}')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句