I have the following kind of document:
{
"_id" : ObjectId("538d64a11ca6e50941fda4d9"), "_id" : "538d518e20b8fd642e0000e8",
"posts" : "some stuff", "date" : "2014-06-02"
}
Using comparison operators for a string date (Not the Mongodb ISODate) works:
> collection.find({"date": {"$gte": "2014-06-02"}})
So why shall we (bother to) convert string dates to an ISODate then?
Probably the biggest advantage of using the MongoDB BSON Date type instead of a string is that you can only use the aggregate
Date operators with BSON Date values.
But if you don't need to do any aggregation of your data, using a sortable string format to represent dates is fine and often cleaner as you don't need to deal with time zone related display problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With