skip to Main Content

I want to store previous data and the new data in the same child using realtime database in android studio but it store only the new data and deleting the previous data

2

Answers


  1. You cannot store new and previous data in a single child in firebase, as it overwrites the previous data.
    Still you can create a child under its parent and update them.

    Login or Signup to reply.
  2. In case you mean you don’t want to overwrite data:

    databaseRef.child("categories").push().setValue(category) 
    

    using push() will always generate new key and then adds the your data to "categories"

    while:

    databaseRef.child("categories").setValue(category)
    

    will always overwrite it ..

    Hope this helps .. more about how to write to realtime-database here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search