Reputation: 35
well i have a "table" named users and i want to know the number of rows (or child), to compare the next user.
for example: in project Ace, i have this users I am the user MDSxw i would compare with the next (DX47d), but i don't know the name (DX47d).
In a SQL database i could use a rowcount to know the size of table and with this get the next user and kwon if this is the last user of table
I would know how do it in the firebase, or a way to do something like this.
Upvotes: 0
Views: 40
Reputation: 598765
If you know at what user to start, you can simply do a limitToFirst(2)
. So:
DatabaseReference usersRef = FirebaseDatabase.getInstance().getReference("users");
Query twoUsers = usersRef.orderByKey().startAt("MDSxw").limitToFirst(2);
twoUsers.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot userSnapshot: dataSnapshot.getChildren()) {
System.out.println(userSnapshot.getKey());
}
}
Upvotes: 1