Shoaib Anwar
Shoaib Anwar

Reputation: 849

Firebase orderByChild on startAt() and endAt() return wrong results

I am searching record from Firebase Database on the formated date rang converted in String type. I am calling filtering query on requestPlaceDate.

Query query = ordersDatabaseRef.limitToFirst(1000).orderByChild(ConstanceFnc.requestPlacedDate).startAt(startDate).endAt(endDate);
    query.addListenerForSingleValueEvent(orderListener);

enter image description here

Firebase return data including previous and next dates, not return specific date range data, what I am expecting from a query on startAt() and endAt()

Upvotes: 0

Views: 302

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 138824

I am searching record from Firebase database on the formated date rang converted in String type.

You aren't getting the desired results because your requestPlacedDate field holds a String and not a Timestamp. When you order String elements, the order is lexicographical. I answered a similar question, so please check my answer from the following post:

To accomplish the correct order for your results, you should change the type of your field to be Timestamp, as explained in my answer from the following post:

Once your field will hold the Timestamp value, your Query will work perfectly fine.

Upvotes: 1

Related Questions