1

The $lte operator does not seem to work correctly on date fields. I have a document in my database where a Date field is set to "Datum": {"$date":"2015-06-30T00:00:00.000Z"}. On the server side the code to query the documents for a given month is

        self.routes['/getEvents'] = function(req, res) {
        var CalendarId = req.query.CalId;
        var start      = req.query.start;
        var end        = req.query.end;
        console.log('getEvents?CalId=' + CalendarId + '&start=' + start + '&end=' + end);

        var filter = {};
        filter.Datum = {"$gte": new Date(start), "$lte": new Date(end)};
        filter.CalId = CalendarId;

        events.find(filter, function(err,docs) {
            if (err) return next(err);
            res.setHeader('Content-Type','application/json');
            res.statusCode = 200;
            res.send(docs);
        });
    }

If that function is called with start = '2015-06-01' and end= '2015-06-30' than this document is not included in the result set. Only documents with a date < 2016-06-30 are included. I have this application as a local application and as a online application on mongolab.com. In the online version the document is inluded in the result set, but in the local application the document is not included in the result set. The local application uses mongodb 3.0.3. On mongolab I think there is still a 2.6.x version in use.

0 Answers0