Firebase 函数 reading/accessing 剩余节点信息

Firebase functions reading/accessing remaining node information

我已经创建了一个触发器来监视路径 /Messages/{pushId}/originalText,因此只有在该特定节点而不是其他任何地方发生更改时才应该触发。

我想做的是访问剩余的节点数据,例如,我如何需要 /Messages/{pushId}/followers 的节点日期,它与 originalText[=15= 处于同一级别]

样本:

exports.makeUppercase = functions.database.ref('/Messages/{pushId}/originalText')
    .onWrite(event => {

    //how to access data at another node, for example 
    //important/Messages/{pushId}/followers

})
exports.makeUppercase = functions.database.ref('/Messages/{pushId}/originalText')
.onWrite(event => {
    event.data.ref.parent.child('followers').once('value', data => {
        console.log('Your data: ' + data)
    })
})

建议你去看看documentation真的很不错,你想要什么都能找到!

  1. onWrite's documentations says that .onWrite returns a DeltaSnaphsot
  2. DeltaSnaphot 的文档说 DeltaSnaphot.ref() returns 一个 Reference
  3. Reference 的文档包含您需要的所有查询方法,在本例中为 once