0

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

5
  • Please edit the question to show a specific example of a document that should be matched by your query. There's nothing we can do without seeing that your query matches your data in every way. Commented Jul 21, 2020 at 0:46
  • @DougStevenson ok Commented Jul 21, 2020 at 10:37
  • What do you mean you get back an empty array? In the screenshot you are showing as an array that at least has that element Commented Jul 21, 2020 at 11:15
  • What if you subtract one day off the Date you pass to the query? Does it find anything? Commented Jul 21, 2020 at 15:04
  • for the example table, i modified my query to show you what it's content should content. sorry I don't usually post on stackoverflow Commented Jul 21, 2020 at 15:28

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.