【问题标题】:Firebase: Is it possible to update individual children across multiple parents?Firebase:是否可以跨多个父母更新单个孩子?
【发布时间】:2017-10-11 06:17:04
【问题描述】:

是否可以在不覆盖其他孩子的情况下跨多个父母更新单个孩子?

我的 Firebase 数据如下所示:

notifications:
    uniquenotif1:
        a: true
        b: true
    uniquenotif2:
        a: true
        b: true

我尝试使用 Swift 仅更新名称为 a 的孩子:

notificationsRef.updateChildValues([uniquenotif1: [a:false], uniquenotif2: [a:false])

这样得到的数据如下:

notifications:
    uniquenotif1:
        a: false
    uniquenotif2:
        a: false

这就是我希望它们看起来的样子:

notifications:
    uniquenotif1:
        a: false
        b: true
    uniquenotif2:
        a: false
        b: true

要求这需要作为单个操作发生(我正在使用 Cloud Functions 发送取决于这些值的推送通知)。

如果可能的话,我不想传递所有孩子的值(a AND b)。

【问题讨论】:

  • 让得到完整的孩子然后更新预期的孩子。

标签: ios swift firebase firebase-realtime-database google-cloud-functions


【解决方案1】:

请看一下:

let key = ref.child("notifications").childByAutoId().key
let noti = ["a": false,
            "b": true]
let childUpdates = ["/notifications/\(key)": noti]
ref.updateChildValues(childUpdates)

您需要一个for 循环来生成一系列请求。这是我的意见。如果您有更好的解决方案,请告诉我。 ^^

【讨论】:

  • 我有一个限制,除了正在更新的值之外,我不能传入任何其他值。
  • 限制?你能告诉我更多吗?
  • 我有一些云函数可以监听这些值的变化
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-17
  • 1970-01-01
相关资源
最近更新 更多