【问题标题】:How to update certain data如何更新某些数据
【发布时间】:2019-05-21 20:35:26
【问题描述】:

有一个对象,其中用户是数组的形式,如何更新一个特定id的用户,而不发送整个用户数组。

const users = firebase.ref().child('users');
users.set(usersArray);

// data is stored in this form
{
  users: [
    {
      id: userId,
      ...
    },
    {
      id: userId,
      ...
    }
  ]
  ...
}

同时更新不同用户的数据时,发送的数据会被覆盖,但必须不被覆盖

【问题讨论】:

    标签: firebase firebase-realtime-database


    【解决方案1】:

    你可以使用 update 或 set with merge true 来做

    set(
      {a: {b: {c: true}}},
      {merge: true}
    )
    With update you can also use field paths for updating nested values:
    
    update({
      'a.b.c': true
    })
    

    参考:Difference between set with {merge: true} and update

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-19
      • 2017-07-29
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多