Mastering Firebase for Android Development
上QQ阅读APP看书,第一时间看更新

Deleting data

To delete data, you can call the removeValue() method onto database reference. You can likewise pass null to the setValue() method, which does the same delete operation:

//Removes the entire child
mDbRef.child(userId).removeValue();
//Passing null to remove the calue
mDbRef.chile(userId).child("name").setValue(null);

// Similarly Hashmap can also be removed
Map<String, Object> mHashmap = new HashMap<>();

mHashmap.put("Name 1/title", null);
mHashmap.put("Name 1/content", null);
mHashmap.put("Name 2/title", null);
mHashmap.put("Name 2/content", null);

The following screenshot shows the Firebase console reaction for the delete operation: