PerSpiKyliaTor
PerSpiKyliaTor

Reputation: 91

remove pushed item from firebase

How can I remove pushed item with a specific value? I have some pushed items with 2 keys: deviceToken and UserID. I need to remove item with the specific deviceToken.

    dev-app
        push
            asdasdasdasda(generated key)
                deviceToken: 12345678
                userID: qwerty
            dgfgdfghhdfgd(generated key)
                deviceToken: 87654321
                userID: sdaerty

    I need to remove the the 1-st one (which has a DeviceToken with value "12345678").

Upvotes: 0

Views: 1169

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600131

To get the child items based on deviceToken, you can execute a query like this:

Firebase ref = new Firebase("https://dev-app.firebaseio.com/push");
Query queryRef = ref.orderByChild("deviceToken").equalTo(12345678);
queryRef.addChildEventListener(new ChildEventListener() {
  @Override
  public void onChildAdded(DataSnapshot snapshot, String previousChild) {
    System.out.println(snapshot.getKey());
  }
  // ....
});

I just copied this snippet from the Firebase documentation on queries and modified it to you data.

Upvotes: 3

Related Questions