MongoDB date comparison
How MongoDB performs date comparison? I tried a few test on the MongoDB
shell:
> db.test.insert( { "dates" : [ new Date("Jul 21, 1983"), new Date("Aug 7,
1999") ] } )
"ok"
> db.test.find()
[
{ "_id" : { "$oid" : "5201e8b7cc93742c160bb9d8" }, "dates" : [
"Thu Jul 21 1983 00:00:00 GMT+0200 (CEST)", "Sat Aug 07 1999 00:00:00
GMT+0200 (CEST)" ] }
]
Now I'll try to get all objects with a date in dates greater than Aug 30,
2000.
> db.test.find( { "dates" : { $gt : new Date("Aug 30, 2000") } } )
[
]
As expected, the document doesn't match. Using "Aug 30, 1999", instead...
> db.test.find( { dates : { $gt : new Date("Aug 30, 1999") } } )
[
{ "_id" : { "$oid" : "5201e8b7cc93742c160bb9d8" }, "dates" : [
"Thu Jul 21 1983 00:00:00 GMT+0200 (CEST)", "Sat Aug 07 1999 00:00:00
GMT+0200 (CEST)" ] }
]
The document matches! What am I missing?
No comments:
Post a Comment