I have a data record in my mongodb collection with the field "birth_date" set to "1983-05-06T16:26:32.613Z".
Below is the find query I used to retrieve this record within a specific date range:
var birthYear = 1983;
var birthDateStart = new Date('1.1.' + birthYear);
var birthDateEnd = new Date('12.30.' + birthYear);
var cursor = db.collection('users').find({
birth_date: {$gte: birthDateStart, $lt: birthDateEnd}
})
It seems like the issue lies in the date format. How can I get the same Date() format as the one stored in the database?
I utilized variety tool to analyze the DB schema:
+--------------------------------------------------+
| key | types | occurrences | percents |
| ------------ | -------- | ----------- | -------- |
| _id | ObjectId | 1 | 100.0 |
| bio | String | 1 | 100.0 |
| birth_date | String | 1 | 100.0 |
+--------------------------------------------------+
As I am using the 'mongodb' package for express.js, I encountered an error when trying to use ISODate().
ReferenceError: ISODate is not defined