node.jsmongodbmongoose

How to do greater than syntax in a Mongoose.js query


How do I get a 'greater than' syntax to work for this Mongoose query?

var where = {};
where._id = req.wine.id;
where.sameAs = undefined;
where.scoreTotal > 0; //THIS NEEDS TO SET TO DO GREATER THAN 0
where.mode = 'group';
where.deleted = false;
Wine.find(where, callback).populate('user');

It keeps crashing my node server.

I'd like to keep this where object syntax instead of doing the inline where object syntax for readability sake. Could I do something like:

where.scoreTotal = $gt(0);

Solution

  • Refer official documentation for clear explanation & complete usage detais : http://mongoosejs.com/docs/queries.html

    Instead of where.scoreTotal > 0
    Add "where.scoreTotal" : { $gt : 0}