My question is an extension of this one MongoDB/Mongoose querying at a specific date?
I have a model Tournament. They will have games on multiple dates. I want to query for tournaments that have games on a certain date. I tried to used the method described in the post.
Example data
{
"_id": {
"$oid": "59a70655b300012a044b2a48"
},
...,
"gameDates": [
{
"$date": "2017-09-01T05:59:59.000Z"
},
{
"$date": "2017-09-02T05:59:59.000Z"
}
]
}
Using mlab, this returns nothing. If I query for specific $date, not a range, it works in mlab, not mongoose.
{
"gameDates": {
"$date": {
"$lt": "2017-09-02T00:00:00.000Z"
}
}
}
Update: In node,
var conditions={gameDates: { $date: '2017-09-01T05:59:59.000Z' } };
var results='gameDates';
Tournament.find(conditions, results).exec(
function(err, tournament) {
if (err) {
console.log("err"+err);
}
console.log("tournament",tournament);
});
Gives me
errError: Can't use $date with Array.