T
T
tuxx2015-11-17 23:29:40
JavaScript
tuxx, 2015-11-17 23:29:40

How to get data from MongoDB by date in Node.js?

To work with MongoDB I use node-mongodb-native . I need to update some records once a day. To get them, I write the following code:

var date = new Date;
date.setDate(date.getDate()-1);
itemsDB.find({
        name: item.name,
        date: {$gte: date.toISOString()}
}).toArray(function(doc)
{
        // обработка пришедших документов
});

Nothing is returned from the database although there are suitable entries. The requested date is correct. If I write a similar request in the mongo console, then I get everything as it should.
UPD . At the moment, I solved the problem by converting all dates to unixtime format

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question