I was keeping the scores of users in the users table. But it is no longer needed. So I want to delete the point of each user. How can I do that ?
CodePudding user response:
There is no magic here. You'll have to read all users, loop over them, and then delete their points one-by-one, or through a multi-path update.
Something like:
DatabaseReference usersRef = FirebaseDatabase.getInstance().getReference("UsersExample");
usersRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Map<String, Object> updates = new HashMap<>();
for (DataSnapshot userSnapshot: dataSnapshot.getChildren()) {
updates.put(userSnapshot.getKey() "/point", null); // Setting to null will delete that node
}
userRef.updateChildren(updates);
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException();
}
}