Filtering records in MongoDB using a date value
In a MongoDB collection i have a record as follows :
{ "_id" : ObjectId("4d0d3945e69a56cf504375b7"), "action" : "Click", "dt" : "Sun Dec 19 2010 03:44:21 GMT+0000 (UTC)","url":"http://www.google.com"}
If i search using db.mycollection.fin开发者_运维百科d({url:'http://www.google.com'})
,the record shows up, but if i search by the date parameter using db.mycollection.find({dt:'Sun Dec 19 2010 03:44:21 GMT+0000 (UTC)'})
the record does not show up.
What is wrong about command db.mycollection.find({dt:'Sun Dec 19 2010 03:44:21 GMT+0000 (UTC)'})
?
Please Help Thank You
It does work :
> db.test.save({ "_id" : ObjectId("4d0d3945e69a56cf504375b7"), "action" : "Click", "dt" : "Sun Dec 19 2010 03:44:21 GMT+0000 (UTC)","url":"http://www.google.com"})
> db.test.find({dt:'Sun Dec 19 2010 03:44:21 GMT+0000 (UTC)'})
{ "_id" : ObjectId("4d0d3945e69a56cf504375b7"), "action" : "Click", "dt" : "Sun Dec 19 2010 03:44:21 GMT+0000 (UTC)", "url" : "http://www.google.com" }
Generally you'll want to save dates as dates rather than strings though.
精彩评论