Firebase removes node based on child value

I want to delete the entire node by request, for example 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" 
+5
source share
1 answer

To remove all links with a child element having a specific value, you will need to extract all the keys ('-KVpQFXnzQkzzrowHxGk', '-KVpQFXnzQkzzrowHxGk' in your case) with an equalTo request, and then remove these links using the remove function.

Here is a sample code.

 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(); }); }); 
+6
source

Source: https://habr.com/ru/post/1259337/


All Articles