Chandra Sekhar Chandra Sekhar - 2 months ago 8
Android Question

Unable to restrict number of records to be fetched to client in firebase Android

My Query:

Query query = mDatabase.child("feeds").child(id).orderByChild("fTime");
query.limitToFirst(20);


I am expecting to receive only 20 records, but it actually returns me all the records available. How do I restrict the fetched record counts?

My Data structure:

feeds : {
feedId : {
fName : name1,
fTime : 123
}
}


My Rules:

{
"rules": {
".read": "auth != null",
".write": "auth != null",
"feeds" : {
".indexOn": ["fTime"]
}
}
}

Answer

Calling limitToFirst returns a new query. Whereas you are expecting it to modify the current reference.

Instead try this:

Query query = mDatabase.child("feeds").child(id).orderByChild("fTime");
Query limitQuery = query.limitToFirst(20);
Comments