当我删除数据库的所有其他字段时,我无法更新firebase上的一个字段
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);
这是JSON树,在eventmodel上想要更新-KTVAt0NM1Y5v32YxSqc并将名称hola更改为新名称
{
"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"
}
}
}
&#13;
答案 0 :(得分:1)
您正在使用只有名称字段的新空对象..
尝试仅更新名称而不是整个对象
:paste -raw