Firebase Query don't show all the data

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Firebase Query don't show all the data



I need to get all users of a determined age range, but my code does not work.



My Firebase database structure is this.


-user
-1
-name:"James"
-age:"21"

-2
-name:"Artur"
-age:"25"

-3
-name:"Charlotte"
-age:"25"

-3
-name:"Marvin"
-age:"80"



My code is this. With this I just catch 1 user.


DatabaseReference uRef = database.getReference("users");

Query UserQuery = uRef.orderByChild("age").startAt(21).endAt(50);

UserQuery.limitToFirst(10).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

int counter =(int) dataSnapshot.getChildrenCount();

Log.d("TAG////////", String.valueOf(counter));




}


@Override
public void onCancelled(DatabaseError databaseError) {

}
});



But if I delete the endAt() condition, I catch all users after 21 and I just wanna catch the users in the range.


DatabaseReference uRef = database.getReference("users");

Query UserQuery = uRef.orderByChild("age").startAt(21); //I deleted endAt(50);

UserQuery.limitToFirst(10).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

int counter =(int) dataSnapshot.getChildrenCount();

Log.d("TAG////////", String.valueOf(counter));




}


@Override
public void onCancelled(DatabaseError databaseError) {

}
});



Please help me.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Makefile test if variable is not empty