Javascript 使用firebase云函数更新另一个位置onUpdate

Javascript 使用firebase云函数更新另一个位置onUpdate,javascript,firebase,firebase-realtime-database,google-cloud-functions,Javascript,Firebase,Firebase Realtime Database,Google Cloud Functions,我正试图保持一些数据与firebase云功能一致。当主列表中的数据发生更改时,我希望用户最喜爱的列表中的所有数据都发生更改 目前,我可以调用该函数并获取正在更改的正确数据的日志,但我的查询不起作用。我得到以下错误: TypeError:ref.update不是函数 在exports.itemUpdate.functions.database.ref.onUpdate中 这是我的密码: const functions = require('firebase-functions'); const a

我正试图保持一些数据与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);
});
我不确定我会错在哪里,我感谢所有帮助和指导来解决这个问题

干杯。

返回一个对象。然后,您尝试对该对象调用
update()
。请注意,在链接的API文档中,Query没有update()方法。您不能简单地“更新”尚未执行的查询。您必须实际使用执行查询,在返回的promise中迭代快照的结果,并使用找到的数据执行进一步的更新。

请参见,