I need the help to query long collection with date range. See the below example document. I wanna query startTime field using date range.
Cloud Firestore doesn't support native indexing or search for text fields in documents. Additionally, downloading an entire collection to search for fields client-side isn't practical. To enable full text search of your Cloud Firestore data, use a dedicated third-party search service.
There are two ways to retrieve data stored in Cloud Firestore. Either of these methods can be used with documents, collections of documents, or the results of queries: Call a method to get the data. Set a listener to receive data-change events.
To convert a Firestore date or timestamp to a JavaScript Date, we use firebase. firestore. Timestamp. fromDate to convert the a date to a Firestore timestamp.
Since I have the dueDate
field stored as "timestamp" (and NOT as string or number) on Cloud Firestore, I did this to get the invoice documents with a due date on 2017:
let start = new Date('2017-01-01'); let end = new Date('2018-01-01'); this.afs.collection('invoices', ref => ref .where('dueDate', '>', start) .where('dueDate', '<', end) );
NOTE: dueDate
field was stored at firebase with a Date() object. e.g.: this.doc.dueDate = new Date('2017-12-25')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With