1

i'm trying to query my mongoDB collection but can't get results.

this is my nodeJS code:

db.collection('events', function (err, collection) {
    var now = new Date().toISOString();
    var query = {endTime:{$gte:{$date: now}}};
    console.log(query); // --> { endTime: { '$gte': { '$date': '2017-10-18T08:31:04.864Z' } } }

    collection.find(query).toArray(function(err, items) {
        console.log(items); // --> []
    });
});

but if i run this query via mongoDB Compass

{ endTime: { "$gte": { "$date": "2017-10-18T08:31:04.864Z" } } }

it works! (12 results)

any help? i think i'm missing something really basic here. thanks

pumpkinzzz
  • 2,907
  • 2
  • 18
  • 32
  • 1
    `{endTime:{$gte: new Date() }}`. `$date` is not a real thing, but a BSON serialization from [MongoDB extended JSON](https://docs.mongodb.com/manual/reference/mongodb-extended-json/). Which is not supported in the driver. – Neil Lunn Oct 18 '17 at 08:41
  • @NeilLunn thanks! I didn't know about that $date thing – pumpkinzzz Oct 18 '17 at 08:53

0 Answers0