Just a little question :
Now i have this structure
images
---- uniqueId
-------- id_logement : 1747657
-------- image : dataimage
---- uniqueId
-------- id_logement : 1747657
-------- image : dataimage
---- uniqueId
-------- id_logement : 985445234
-------- image : dataimage
And it's better ! Thank you !! but :
How can i remove all the images where id_logement = 1747657 ?
i tried that
firebase.database().ref('logements/'+key).remove();
firebase.database().ref('geofire/'+key).remove();
firebase.database().ref('images').child('id_logement').equalTo(key).remove();
with key = 1747657 but without success for the images ! This UniqueId makes me nervous ! Please can you send me more advices ? thank you very much
Just a little question :
Now i have this structure
images
---- uniqueId
-------- id_logement : 1747657
-------- image : dataimage
---- uniqueId
-------- id_logement : 1747657
-------- image : dataimage
---- uniqueId
-------- id_logement : 985445234
-------- image : dataimage
And it's better ! Thank you !! but :
How can i remove all the images where id_logement = 1747657 ?
i tried that
firebase.database().ref('logements/'+key).remove();
firebase.database().ref('geofire/'+key).remove();
firebase.database().ref('images').child('id_logement').equalTo(key).remove();
with key = 1747657 but without success for the images ! This UniqueId makes me nervous ! Please can you send me more advices ? thank you very much
Share Improve this question edited Jul 31, 2016 at 15:34 Frank van Puffelen 599k85 gold badges889 silver badges859 bronze badges asked Jul 31, 2016 at 6:03 Pablo DelaNochePablo DelaNoche 6771 gold badge11 silver badges30 bronze badges 1- Hey Pablo, just added an answer. Sorry on the delay. Regards. :) – adolfosrs Commented Jul 31, 2016 at 13:25
3 Answers
Reset to default 10Since you want to bulk delete data based on a query, you will need to retrieve it first and delete it setting its values to null and mitting the changes with update
.
const ref = firebase.database().ref('images');
ref.orderByChild('id_logement').equalTo(key).once('value', snapshot => {
const updates = {};
snapshot.forEach(child => updates[child.key] = null);
ref.update(updates);
});
Working jsFiddle.
There is actually an easier way.
Just call the ref
property in your snapshot, and use .on('child_added',...)
var ref = firebase.database().ref('images');
ref.orderByChild('id_logement').equalTo(key).on('child_added', (snapshot) => {
snapshot.ref.remove()
});
Try this code:-
rootRef.child("images").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for(DataSnapshot dataSnapshot : snapshot.getChildren())
{
if(dataSnapshot.child("id_logement").getValue().toString().equals("1747657"))
{
dataSnapshot.getRef().setValue(null);
}
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});