Mongodb : Why convert string date to ISOdate if comparison operators work?

心不动则不痛 提交于 2019-12-23 15:42:57

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/25686847/mongodb-why-convert-string-date-to-isodate-if-comparison-operators-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!