Eric Retamero
Eric Retamero

Reputation: 51

Cannot update one field on firebase - Android

I cannot update one field on firebase, when i do delete all the others fields of the database

CODE

        String URL_EVENT_REFERENCE = "eventmodel";
        FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference databaseEvent = database.getReference(URL_EVENT_REFERENCE);
        String key = "KTVAt0NM1Y5v32YxSqc";          
        Map<String, Object> eventValues = new HashMap<>();
        eventValues.put("name", "new name");    
        Map<String, Object> childUpdates = new HashMap<>();
        childUpdates.put(key, eventValues); 
        databaseEvent.updateChildren(childUpdates);

This is the JSON tree, on the eventmodel y want to update the -KTVAt0NM1Y5v32YxSqc and change the name hola to new name

{
  "eventmodel" : {
    "-KTVAt0NM1Y5v32YxSqc" : {
      "info" : "",
      "limit" : 2,
      "members" : {
        "Mn7gZ7rn5XRGU1HXujbbSQv05BH2" : true
      },
      "name" : "hola",
      "pic" : "default_publish_img",
      "place" : {
        "address" : "Barcelona, España",
        "latitude" : 41.3850639,
        "longitude" : 2.1734034999999494
      },
      "status" : true,
      "timeCurrentEnd" : "7/10/2016 21:27",
      "timeCurrentStart" : "7/10/2016 20:27",
      "uidLeader" : "Mn7gZ7rn5XRGU1HXujbbSQv05BH2"
    }
  }
}

Upvotes: 1

Views: 692

Answers (1)

Yarden Cohen
Yarden Cohen

Reputation: 594

You are putting new empty object with only name field..

try to update only the name instead of the whole object

databaseEvent.child(key).child("name").setValue("new name");

Upvotes: 1

Related Questions