Hello @Nathan_Hazout,
Can I still run date time queries on it, even though it’s not stored as an ISODate object or any other structured class?
Yes. You can still run queries on the date field.
Would mongodb be smart enough to treat them as such?
MongoDB will treat them as they are - string data type. And, the string comparison rules will apply. You can safely store dates as strings and query on them as long as they are properly formatted for date, i.e., “YYYY-MM-ddTHH:mm:ss”.
Or anything I can do to improve my situation?
Your situation is not bad, I think.
Suppose you have a documents like this:
{ _id: 1, date: "2020-07-25T14:10:26.113Z" }
{ _id: 2, date: "2020-07-29T07:55:55.485Z" }
{ _id: 9, date: "2020-08-01T01:00:12.002Z" }
An example query to find documents which have date greater than the given date (also of type string):
db.test.find( { date: { $gt: "2020-07-25" } } )
The above query fetches all the documents. Then, you can also query like this:
db.dates.find( { date: { $gt: "2020-07-25", $lte: "2020-07-31" } } )
This is also the case with the aggregation queries. And, in case you need to match using date
objects, there are aggregation date operators to convert to specific format (string to date object or vice-versa).
That said, please do tell about any specific type of queries you have in your application.