Hi,
I am having this especially weird issue, that is turning me crazy ! I am centralising data on my Atlas Cluster from bare-metal servers running community MongoDB databases locally. However I have an issue with my ISODates() attributes that are converted to “$date” dictionnaries, after which the sort() query still works but the “$lt” and “$gt” queries are failing.
Attribute in local db
"createdTime": ISODate("2023-01-20T11:20:50.268Z")
Attribute in the Atlas Cluster’db :
"createdTime" : { '$date': '2023-01-20T11:20:50.268Z' }
In my Atlas Cluster’s collection I am still able to sort on the time attribute :
db.MyCollection.find().sort({createdTime:-1}).map(x => x.createdTime)
[
{ '$date': '2023-01-20T11:20:50.268Z' },
{ '$date': '2023-01-20T11:20:26.587Z' },
{ '$date': '2023-01-20T11:20:04.108Z' },
]
But when I try to use the operators “$gt” and “$lt” then mongo doesn’t know what to do :
db.MyCollection.countDocuments({ createdTime: { $lt: ISODate("2023-02-01T00:00:00.000Z")} })
0
// even with "$date" as a key
db.MyCollection.countDocuments({ "createdTime.$date": { $lt: ISODate("2023-02-01T00:00:00.000Z")}})
0
Eventually I figured I could make it work with a Javascript function to convert the “$date” objects back to ISODate, but I want to be able to use the “$lt” and “$gt” in my python API, relying on pymongo.
Any idea how I could solve what I assume is a date formatting issue ?
Thanks a lot for your help, apologies if this is the wrong place to ask.