Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 997
madim Avatar asked May 31 '16 18:05

madim


1 Answers

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.

like image 63
Dennis Alund Avatar answered Oct 05 '22 13:10

Dennis Alund