Smee
Smee

Reputation: 143

Android Firebase - Is it possible to use limitToFirst()/limitToLast() in between startAt() and endAt()

Is it possible to have its query something like this

postRef
   .orderByChild("dateCreated")
   .startAt(startDate)
   .limitToFirst(5)
   .endAt(endDate)

Upvotes: 0

Views: 1018

Answers (2)

neo73
neo73

Reputation: 464

I have always used limitToLast in the end.

Query query=mDatabase.getReference().child("posts").orderByChild("date").limitToLast(1);

https://firebase.google.com/docs/reference/js/firebase.database.Query

Take a look at this link maybe you will find what you need.

Upvotes: 1

AlexTa
AlexTa

Reputation: 5251

Yes, it is possible.

But, for better code comprehension you should define the range of your search first, and then limit the results count.

postRef.orderByChild("dateCreated").startAt(startDate).endAt(endDate).limitToFirst(5)

Upvotes: 0

Related Questions