Mongoose query to pull data between two datetimes
<p>I have a mLab db set up and interacting with it through Mongoose. I want to query the db and return all records within a 10 min window. So at the time of the query, it will look at the date field and bring back all records within 10 min before the current datetime and within 10 min after the current datetime.</p>

<p>A db entry looks like this : </p>

<pre><code>{ 
  "_id" : ObjectId("572cd34786d87203006a89dc"), 
  "expecting" : "Chris", 
  "channel" : "D164Z16BB", 
  "date" : ISODate("2016-05-06T13:30:00Z"), 
  "userId" : "U0GMSLZ7C", 
  "email" : "email@gmail.com", 
  "userName" : "userName", 
  "firstName" : "Bob", 
  "__v" : 0 
}
</code></pre>

<p>My query looks like :</p>

<pre><code>var now = new Date();
var later = moment(now).add(15, 'm').toDate();
var earlier = moment(now).subtract(15, 'm').toDate();

Schedules.find({
    'date': {
       '$gte': earlier,
       '$lte': later
     }
}, function(err, schedules) {
    if(err) res.send(err);
      res.json(schedules);
});
</code></pre>

<p>Even when there is an entry in the db that meets the time criteria, it is not returning anything.</p>

<p>Post request : </p>

<pre><code>apiRouter.post('/', function(req, res) {
    console.log(req.body);
    var schedule = new Schedules();

    schedule.firstName = req.body.firstName;
    schedule.real_name = req.body.real_name;
    schedule.userName = req.body.userName;
    schedule.email = req.body.email;
    schedule.userId = req.body.userId;
    schedule.date = req.body.date;
    schedule.channel = req.body.channel;
    schedule.expecting = req.body.expecting;

    schedule.save(function(err, schedule) {
        if (err) res.send(err);
        res.json({message: 'Schedule was created'});
    });
});
</code></pre>