Champ Decay
Champ Decay

Reputation: 228

How to Remove Specific object from firebase Realtime Database

How to remove specific object from Firebase DB. I want to remove fine message from [email protected] username.

I have tried following code and i got proper object but remove() not works.

abcd = ref.orderByChild('message').equalTo('fine');
abcd.on('value', function(abcdSnap){
    console.log(abcdSnap.val());
})

above Code returns -L-Kl8ctoi5j4TtMWTsc but now how to remove this object. i tried to remove() as follows but not working...

abcd = ref.orderByChild('message').equalTo('fine').remove();

abcd.on('value', function(abcdSnap){
   abcdSnap.remove();
})

Upvotes: 2

Views: 1412

Answers (2)

Champ Decay
Champ Decay

Reputation: 228

Okay Finally Got the Answer.

abcd = ref.orderByChild('message').equalTo(msg);
abcd.on('value', function(abcdSnap){
    var a = abcdSnap.val();
    var b = Object.keys(a)[0];
    ref.child(b).remove();
})

Upvotes: 1

HemalHerath
HemalHerath

Reputation: 1056

public void removeUserData()
{
    databaseReferenceC = FirebaseDatabase.getInstance().getReference("users/profiles/");
    FirebaseUser user = firebaseAuth.getCurrentUser();
    databaseReferenceC.child(user.getUid()).removeValue();
}

as a example you can use something like that use removeValue()

Upvotes: 0

Related Questions