willkoua
willkoua

Reputation: 115

firestore: array empty when i try to get data by date

This is my first time using Firestore. I am not able to get the data from firestore when I add filter by date. I would like to retrieve firestore data save the day before (yesterday). i trying many internet's examples.

i try this:

const query = this.fb.collection('your_collection');
query(`your_directory`,
  ref =>  ref.orderBy('reportedAt').startAt(new Date(2020, 7, 20, 0, 0, 0)));

and this

const query = this.fb.collection('your_collection');
query(`your_directory`,
  ref =>  ref.where('reportedAt','>=', new Date(2020, 7, 20, 0, 0, 0)));

but every time I use one of these methods, I do not find the expected results. he return an empty array.

Could someone explain to me how to solve my problem?

EDIT: response example. Array this data enter image description here I would like to retrieve a data array whose reportedAt dates from the last day. this is reportedAt on firebase UI enter image description here enter image description here

thanks

Upvotes: 0

Views: 171

Answers (1)

willkoua
willkoua

Reputation: 115

finally my request to work and I still do not understand...

this query don't work

const query = this.fb.collection('your_collection');
query(`your_directory`,
ref =>  ref.orderBy('reportedAt').startAt(new Date(2020, 7, 20, 0, 0, 0)));

but this query work

const query = this.fb.collection('your_collection');
query(`your_directory`,
ref =>  ref.orderBy('reportedAt').startAt(new Date("2020-07-20")));

the difference is in the way of instantiating the Date object. But as I told you I do not understand this behavior.

Upvotes: 1

Related Questions