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);
MongoDB provides different types of comparison operators and greater than equals to operator($gte) is one of them. This operator is used to select those documents where the value of the field is greater than equals to(>=) the given value. You can use this operator in methods (like, find(), update(), etc.)
$gte selects the documents where the value of the field is greater than or equal to (i.e. >= ) a specified value (e.g. value .)
The value of the $in operator is an array that contains few values. The document will be matched where the value of the breed field matches any one of the values inside the array.
Mongoose | findOne() Function The findOne() function is used to find one document according to the condition. If multiple documents match the condition, then it returns the first document satisfying the condition.
You can use query like
Person.
find({
occupation: /host/,
'name.last': 'Ghost',
age: { $gt: 17, $lt: 66 },
likes: { $in: ['vaporizing', 'talking'] }
}).
limit(10).
sort({ occupation: -1 }).
select({ name: 1, occupation: 1 }).
exec(callback);
or using query builder
Person.
find({ occupation: /host/ }).
where('name.last').equals('Ghost').
where('age').gt(17).lt(66).
where('likes').in(['vaporizing', 'talking']).
limit(10).
sort('-occupation').
select('name occupation').
exec(callback);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With