node.js 如何在 Mongoose.js 查询中做大于语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35883196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to do greater than syntax in a Mongoose.js query
提问by tonejac
How do I get a 'greater than' syntax to work for this Mongoose query?
我如何获得一个“大于”语法来处理这个 Mongoose 查询?
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 对象语法,而不是内联 where 对象语法。我可以做这样的事情:
where.scoreTotal = $gt(0);
回答by codeGig
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);
回答by Abhishek Kulkarni
Refer official documentation for clear explanation & complete usage detais : http://mongoosejs.com/docs/queries.html
请参阅官方文档以获得清晰的解释和完整的使用细节:http://mongoosejs.com/docs/queries.html
Instead of where.scoreTotal > 0
Add "where.scoreTotal" : { $gt : 0}
而不是where.scoreTotal > 0
添加"where.scoreTotal" : { $gt : 0}

