Increment and update in Firebase

Let's assume that you have the following object:

json
{
    'name': 'Erik',
    'age': 30,
    'posts': {
        '-MMFpPpFFi3CjLARb59_': 'Hi'
    }
}

To increment the value of a property, you can use firebase.database.ServerValue.increment().

For example, if you wanted to increment the value of age and update name at the same time:

javascript
let object = {
    
    name: 'Erik Martín Jordán',
    age: firebase.database.ServerValue.increment(1)
    
}

// Calling update method
firebase.database().ref().update(object);

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.