I am trying to find expired session by running query on this collection
{
"_id" : ObjectId("4e4e88b81144e5a658000000"),
"__meta" : {
"id" : "3a72c90f8455e2fd4b8a05ffa04b870a8672f1a9",
"expiration" : "3600",
"timestamp" : 1313769656
}
}
the query
db.sessions.find({$where: function(){
return (this.__meta.timestamp + this.__meta.expiration) <= Math.round(new Date().getTime()/1000);
}})
I am expecting to get the collection, but I get an empty result.
You can use the javascript
parseInt()function to convert a string to an integer. Be sure to use it in the formparseInt(my_string, 10), where the second argument is the integer base; its default behavior is to sense the base automatically, so strings like “0400” are interpreted as octal, not decimal.