Stan Malcolm
Stan Malcolm

Reputation: 2790

Cannot get data from firebase with filter

I am new with firebase, so don't be very strict... I have next database:

{"list":[
          {
             "id":0,
             "name":"name",
             "text":"text"
          },
          {
             "id":1,
             "name":"name",
             "text":"text"
          },
          {
             "id":2,
             "name":"name",
             "text":"text"
          },
          {
             "id":3,
             "name":"name",
             "text":"text"
          }
    ]
}

enter image description here

Here is my code for request:

FirebaseDatabase database = FirebaseDatabase.getInstance();
Query mQuery = database.getReference("list")
                .child("id").startAt("2");
mQuery.addListenerForSingleValueEvent(eventListener);

but this request return null...

Will be glad any idea?

UPDATE

I need to get all items where id is bigger than asked one.

Upvotes: 3

Views: 577

Answers (2)

Rohit Navarathna
Rohit Navarathna

Reputation: 418

Query mQuery = database.getReference("list")
            .child("id").startAt("2");

This query returns nodes at https://<YOUR_FIREBASE_APP>.firebaseio.com/list/id which doesn't exist and so you get a null result.

Try this instead

Query mQuery = database.getReference("list").startAt("2");

Upvotes: 0

Wilik
Wilik

Reputation: 7720

You need to add an order-by method

Query mQuery = database.getReference("list")
            .orderByChild("id").startAt(2);

It should work

Upvotes: 5

Related Questions