0

Image of Database Here

I have a firebase database with "4 Tables".

Each "table" haves data from each object that exists in TLogin. These objects are all identified with an ID value.

What I want to do is to update a specific object value by it´s ID value.

For example, I want to set in the "table" TProgresso the XP value to "10" where the ID haves the value "2".

How can I make this update?

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
Grinnex.
  • 869
  • 2
  • 12
  • 23

1 Answers1

2

You first have to query for the TProgresso sub-nodes that verifies id === 2 and then update the value of xp(s), as follows:

  var db = firebase.database();

  db.ref('TProgresso')
    .orderByChild('id')
    .equalTo(2)
    .once('value')
    .then(function(snapshot) {
      snapshot.forEach(function(childSnapshot) {
        childSnapshot.ref.child('xp').set(10);
      });
    });

You'll find more detail in the doc about the orderByChild() and equalTo() methods.

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
  • 1
    Thank you for your answer! It solved my question! You really deserve those reputation points Thank´s a lot! – Grinnex. Nov 25 '19 at 17:33
  • @cutiko because the nodes with values `-LSJG...` or `-LSJH...` are keys automatically generated by Firebase and the OP does not know them upfront. – Renaud Tarnec Nov 25 '19 at 22:52