In the original request timestamp, this is just a string field, and Date()will be considered as a string in the Mongo shell. Comparing these operands will work like any other string comparison:
$ mongo
MongoDB shell version: 2.2.0-rc1-pre-
connecting to: test
> db.foo.drop()
true
> db.foo.insert({ x: Date() });
> db.foo.find()
{ "_id" : ObjectId("50218e808930273947a21cf3"), "x" : "Tue Aug 07 2012 17:54:09 GMT-0400 (EDT)" }
> sleep(1000)
null
> db.foo.find({ x: { $lt: Date() }});
{ "_id" : ObjectId("50218e808930273947a21cf3"), "x" : "Tue Aug 07 2012 17:54:09 GMT-0400 (EDT)" }
> db.foo.find({ x: { $gt: Date() }});
>
ISODate()is the JS equivalent for Mongo date fields , and it is not comparable to string values ββwhen using $gtor $lt:
> db.foo.find({ x: { $gt: ISODate() }});
> db.foo.find({ x: { $lt: ISODate() }});
> db.foo.find({ x: { $ne: ISODate() }});
{ "_id" : ObjectId("50218e808930273947a21cf3"), "x" : "Tue Aug 07 2012 17:54:09 GMT-0400 (EDT)" }
> db.foo.insert({x: ISODate() });
> db.foo.find({ x: {$gt: Date() }});
> db.foo.find({ x: {$lt: Date() }});
{ "_id" : ObjectId("50218e808930273947a21cf3"), "x" : "Tue Aug 07 2012 17:54:09 GMT-0400 (EDT)" }
> db.foo.find({ x: {$ne: Date() }});
{ "_id" : ObjectId("50218e808930273947a21cf3"), "x" : "Tue Aug 07 2012 17:54:09 GMT-0400 (EDT)" }
{ "_id" : ObjectId("50218fa18930273947a21cf4"), "x" : ISODate("2012-08-07T21:58:57.350Z") }
>
Mongo , , , .
: , -, (, ), TTL, 2.2. .