Search code examples
node.jsfirebasefirebase-realtime-databasefirebase-admin

how to increase value in Realtime Database


 const dataFromDbUser = admin.database().ref('Base/' + 'users/'+ userId);

 dataFromDbUser.on('value',(item)=>{
 item.val().money //10
 })

how can i increase the value of money? Thank you

using node.js

this is what the base looks like

Base:{
   users:{
      22333443:{
         money:10
      }
   }
}

Solution

  • That sounds like a task for ServerValue.increment, so I recommend reading the documentation on atomically incrementing a value?

    This also works from the Admin SDKs. So if you're having a problem making it work, please edit your question to show a minimal repro.