These are chat archives for LearnBoost/mongoose

23rd
Jan 2015
Ilan Biala
@ilanbiala
Jan 23 2015 02:54
Is it possible to do .where('created').lt(new Date('1/20/2015').gt(new Date())? comparing dates works in JS natively when doing >/< or subtracting, so can Mongoose do it?
Ilan Biala
@ilanbiala
Jan 23 2015 04:16
@vkarpov15 do .lt()/.gt() handle everything that $lt/$gt handle? I noticed that $lt/$gt handle dates as String based on some of the Mongoose tests, but do they handle Date objects directly?
Maksim
@chetverikov
Jan 23 2015 04:33

@ilanbiala I don't quite understand what the problem is, but I do like this:


  model.find({ 
    ‘schedule.start’: { $lte: req.query.start },
    ‘schedule.stop’: { $gte: req.query.stop },
 })

req.query.start/stop - is ms or date as string. Everything works perfectly!

Ilan Biala
@ilanbiala
Jan 23 2015 04:34
Right, but can I still do .lte(req.query.start)? And how come I can't pass in a Date object? It should be easier to compare 2 Date objects rather than converting String->Date then comparing.
Maksim
@chetverikov
Jan 23 2015 05:14
You have what is the problem? .lte/.gte doesn't understand the Date object?
Ilan Biala
@ilanbiala
Jan 23 2015 05:15
Yes, that seems to be the issue.
It also seems that $lte doesn't accept the Date object, only the date as a String.
Maksim
@chetverikov
Jan 23 2015 05:21
Strange... I Have all the works:
require('mongoose').model('User').where('created').gte(new Date('2014-12-29')).exec(function(err, result){
  console.log(result);
});
maybe you have wrong type in the schema for created?