Reputation: 133
I want to delete the entire node by query like delete * WHERE user_id = "-KTruPWrYO9WFj-TF8Ft" How can I achieve this on firebase?
-KVpQFXnzQkzzrowHxGk
answer: "1"
question_number: 2
user_id: "-KTruPWrYO9WFj-TF8Ft"
-KVpQFXODhsAMJYFNjy7
answer: "4"
question_number: 25
user_id: "-KTruPWrYO9WFj-TF8Ft"
Upvotes: 8
Views: 7384
Reputation: 1484
To delete all references with child having some particular value first you will need to retrieve all keys ('-KVpQFXnzQkzzrowHxGk', '-KVpQFXnzQkzzrowHxGk' in your case) with equalTo
query and then delete those references with remove
function.
A sample code is here.
var ref = firebase.database(); //root reference to your data
ref.orderByChild('user_id').equalTo('-KTruPWrYO9WFj-TF8Ft')
.once('value').then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
//remove each child
ref.child(childSnapshot.key).remove();
});
});
Upvotes: 14