0
let before1day = new Date().getTime() - (24 * 3600 * 1000 );
const result = await this.firestore.collection(collection).doc(id).collection(subcollection).
               orderBy('time').startAt(before1day).get();
const list = [];
result.forEach(doc => {
  const data = doc.data();
  data.id = doc.id;
  list.push(data);
});

I want to query the data of the last 24 hours, however as I use orderBy and StartAt, it still return the all result without any query.

Wesley
  • 65
  • 9
  • 2
    What type is the `time` field in your document? If that is a `Timestamp`, you have to also pass a `Timestamp` or `Date` to `startAt`: `.startAt(new Date(before1day))`. – Frank van Puffelen Mar 19 '22 at 14:21
  • Yes it is a Timestamp, thanks a lot I had manage to solve the problem by adding new '''Date(before1day)''' – Wesley Mar 20 '22 at 07:08

1 Answers1

0

If the time field in your database is a Timestamp, you have to also pass a Timestamp or Date to startAt, so:

.startAt(new Date(before1day))
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807