admin管理员组文章数量:1340293
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"
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"
Share
Improve this question
edited Nov 6, 2016 at 6:15
Frank van Puffelen
600k85 gold badges890 silver badges860 bronze badges
asked Nov 5, 2016 at 18:15
Edyl Jay TempladoEdyl Jay Templado
1331 silver badge9 bronze badges
1 Answer
Reset to default 14To 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();
});
});
本文标签: javascriptFirebase remove node based on child valueStack Overflow
版权声明:本文标题:javascript - Firebase remove node based on child value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743621171a2511552.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论