【发布时间】:2018-11-17 19:19:03
【问题描述】:
我正在尝试使一些数据与 Firebase 云功能保持一致。当主列表中的数据发生变化时,我希望用户收藏列表中的所有数据都发生变化。
目前,我可以调用该函数并获取正在更改的正确数据的日志,但我的查询不起作用。我收到以下错误:
TypeError: ref.update 不是函数 在exports.itemUpdate.functions.database.ref.onUpdate
这是我的代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.itemUpdate = functions.database
.ref('/items/{itemId}')
.onUpdate((change, context) => {
const before = change.before.val(); // DataSnapshot after the change
const after = change.after.val(); // DataSnapshot after the change
console.log(after);
if (before.effects === after.effects) {
console.log('effects didnt change')
return null;
}
const ref = admin.database().ref('users')
.orderByChild('likedItems')
.equalTo(before.title);
console.log(ref);
return ref.update(after);
});
我不确定我哪里出错了,感谢所有帮助和指导来解决这个问题!
干杯。
【问题讨论】:
标签: javascript firebase firebase-realtime-database google-cloud-functions