madim
madim

Reputation: 804

How to delete multiple nodes in one request in firebase?

I have two nodes from one root and I want to delete the data from both of them in one request. Both sub-nodes has the same key. I tried this:

Firebase firebaseRef = new Firebase(<root_path>);

Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put(<path_to_first_node>, key);
childUpdates.put(<path_to_second_node>, key);

listToRemoveRef.updateChildren(childUpdates, null);

But it removed data from only the first node

Upvotes: 12

Views: 3140

Answers (1)

Dennis Alund
Dennis Alund

Reputation: 3149

It looks like you're using the updateChildren function wrong. What you want to do is this

Firebase firebaseRef = new Firebase(<root_path>);

Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("<path_to_first_node>" + key, null);
childUpdates.put("<path_to_second_node>" + key, null);

listToRemoveRef.updateChildren(childUpdates);

The second parameter to updateChildren doesn't set the value to null it is an optional completion listener (see documentation). So instead of passing null to it on the last line, you can just omit it.

Upvotes: 3

Related Questions