These are chat archives for LearnBoost/mongoose

21st
Feb 2015
Ruben Costa
@rubencosta
Feb 21 2015 12:48

Hi all, i run into something strange and i want to know if i'm doing it wrong with mongoose.

This works on mongo:
db.words.find({$and: [
{text:{$nin:['love']}}, {text:new RegExp('^l')}]},
{_id:0,text:1}).sort({timesDefined:-1}).limit(5)

But when i try to do it in node with mongoose like this:
var query = Word.find({text: new RegExp('^' + req.params.word)}, 'text alias');
if (req.params.sort == '-timesDefined') {
var nin = Array.isArray(req.query.nin) ? req.query.nin : [req.query.nin];
query.nin('text', nin);
sort = {timesDefined:-1};
query.sort(sort)
}
query.limit(5).exec(queryCallback);
with req.params.word = 'l' and req.query.nin = 'love' it gives back love in the result;

Samiran Raj Boro
@srajbr
Feb 21 2015 14:27
Hello my $and does not work as expected. It returns all the documents. Please let me know what did i do wrong http://pastebin.com/vEM7B1Mz
Kilian Ciuffolo
@kilianc
Feb 21 2015 20:49
Hello everyone! I just figured that mongoose doesn't accept subdocuments path but just the final field
if I do a.foo = b.foo where foo is a subdocument it doesn't work, same thing for Foos.create({ foo: { bar: 'bar' } })