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"
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();
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With