Can't compare Date object
See original GitHub issueawait this.webhooksModel.insertMany([
  {
    ...data,
    nextSchedule: new Date()
  }
])
await this.webhooksModels.find(
  {
    nextSchedule: { $lte: new Date() } // new Date(new Date().toISOString())
  }
)
// returns []
If the data type was (new Date).toISOString() it will return data with the following query
await this.webhooksModel.insertMany([
  {
    ...data,
    nextSchedule: (new Date()).toISOString()
  }
])
await this.webhooksModels.find(
  {
    nextSchedule: { $lte: new Date(new Date().toISOString()) }
  }
)
// returns [...data]
However, this will cause problems in the MongoDB itself. We are unable to sort the data if the data type was string instead of Date
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:6 (1 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
python - can't compare datetime.datetime to datetime.date
You can use the datetime.datetime.combine method to compare the date object to datetime object, then compare the converted object with the other datetime ......
Read more >JavaScript Date Comparison – How to Compare Dates in JS
The date object allows us to perform comparisons using the > , < , = , or >= comparison operators, but not the...
Read more >Everything You Should Know about Comparing Dates in ...
So, as an alternative way to compare dates with time in Javascript, we can use the date object's built-in method, getTime . The...
Read more >You Can Compare Dates In Javascript | by Filip Vitas - Medium
I stumbled upon the blog post named You Cannot Compare Dates In Javascript. The title is a bit misleading and it doesn't give...
Read more >How to compare dates with TypeScript or JavaScript
As the title for this section says, we will take a look at direct date comparison, i.e comparing the Date objects directly.
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

@KirianCaumes thank you this was helpful, but I found your workaround only works down to number of day and not hours, seconds, and so on. So for more accurate finding of start/end timestamps use:
A workaround that I use is:
So I can keep date in date format in my db 😉