Problem with find Date from Node to MongoDB:
It's been said MongoDB might not be storing a Date object, but a string, but I'm not sure how to check, or how to fix that.
In my turnys.js file:
exports.findNeededTurnys = function(req, handler)
{
console.log(findNeededTurnys);
var key;
//var arg0 = {$or:[{start:{$lte:new Date()}, $where: this.users.length == this.seats}]};
var arg0 = {start:{$lte:new Date()}};
console.log(findNeededTurnys: arg0=+JSON.stringify(arg0));
turnydb.collection('turnys', function(err, collection)
{
collection.find(arg0, {safe:true}, function(err, result) {
if(err) console.log(findNeededTurnys: find: err=+err);
console.log(findNeededTurnys: find: result=+JSON.stringify(result));
handler.handle(result);
});
});
};
The log files show empty result from MongoDB?:
findNeededTurnys: arg0={start:{$lte:2014-03-31T10:17:48.857Z}}
findNeededTurnys: find: result={}
In Mongo, the query works (after adding new Date caller, as driver might abstract that in the js console.log):
> db.turnys.find({start:{$lte:2014-03-31T10:17:48.857Z}});
> db.turnys.find({start:{$lte:new Date(2014-03-31T10:17:48.857Z)}});
{ gId : ObjectId(5335e4a7b8cf51bcd054b423), seats : 2, start : ISODate(2014-03-31T08:47:48.946Z), end : ISODate(2014-03-31T08:49:48.946Z), rMin : 800, rMax : 900, users : [ ], _id : ObjectId(53392bb42b70450000a834d8) }
// here is a sample of the mongo db
[
{
gId: 5335e4a7b8cf51bcd054b423,
seats: 2,
start: 2014-03-31T08:47:48.946Z,
end: 2014-03-31T08:49:48.946Z,
rMin: 800,
rMax: 900,
users: [],
_id: 53392bb42b70450000a834d8
},
{
gId: 5335e4a7b8cf51bcd054b423,
seats: 2,
start: 2014-03-31T08:47:48.946Z,
end: 2014-03-31T08:49:48.946Z,
rMin: 1000,
rMax: 1100,
users: [],
_id: 53392bb42b70450000a834da
},
...
]