Decrement a value from the server using Firebase

Let's assume the following database structure in Firebase:

JSON
{
    people: {
        erik: {
            age: 30,
            location: 'Barcelona'
        }
    }
}

If you wanted to increase or decrease the age of an object using Firebase functions, you could do:

javascript
const admin = require('firebase-admin');

var app = admin.initializeApp();

exports.increaseAge = functions.https.onRequest((request, response) => { 
    
    admin.database().ref('people/erik').update({
        
        age: admin.database.ServerValue.increment(1)
        
    });
    
    response.sendStatus(200);
    
});

exports.decreaseAge = functions.https.onRequest((request, response) => { 
    
    admin.database().ref('people/erik').update({
        
        age: admin.database.ServerValue.increment(-1)
        
    });
    
    response.sendStatus(200);
    
});

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