0

There is an object in which users are in the form of an array, how to update a user with a specific id, without sending the entire array of users.

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

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

when simultaneously updating the data of different users, the sent data is overwritten, but it is necessary that it is not overwritten

Kovich
  • 61
  • 1
  • 7

1 Answers1

1

You can do using update or 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
})

ref: Difference between set with {merge: true} and update

rijin
  • 1,709
  • 12
  • 21