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.
CodePudding user response:
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))