Avinash Prabhakar
Avinash Prabhakar

Reputation: 483

Updating firebase database in android

I would like to to update the entries in the table instead of replacing them. The code I use currently:

private DatabaseReference mDatabase;  
    mDatabase =FirebaseDatabase.getInstance().getReference().child("Users").child(uid);
    HashMap<String,String> usermap = new HashMap<>();
    usermap.put("name",name);
    usermap.put("description",description);
    usermap.put("address",address);
    mDatabase.setValue(usermap);

removes the email field in Users I had in my database. I googled a bit and it turns out setValue replaces all the data. I tried using updateChildren instead but I get the error:DatabaseReference cannot be applied to java.util.HashMap <java.lang.String,java.lang.String>)

Upvotes: 0

Views: 254

Answers (1)

Deep Patel
Deep Patel

Reputation: 2644

Try something like:


mDatabase=FirebaseDatabase.getInstance().getReference().child("Users").child(uid);
    HashMap<String,Object> usermap = new HashMap<>(); // if you have data in diff data types go for HashMap<String,Object> or you can continue with HashMap<String,String>
    usermap.put("name",name);
    usermap.put("description",description);
    usermap.put("address",address);
    mDatabase.updateChildren(usermap); // Replace this line in your code to update.

Upvotes: 1

Related Questions