Find by date field

I have documents containing a field - “effectiveFrom” that is a date.
I want to filter the documents based on date.

When i run the below query no documents are returned.
db.mydata.find({“effectiveFrom” : {"$lte" : {"$date" : “2021.08.30T17:30:00.465Z”}}})

However when I change the query as below, documents are returned as expected.
db.mydata.find({“effectiveFrom” : {"$lte" : new Date(“2021.08.30T17:30:00.465Z”)}})

I am on MongoDb 3.2. I have tried hard to find why the first query doesn’t work.
Any help highly appreciated.


1 Like

In mongo shell mode $date is not recognized. Hope this helps.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.