如何在Mongoose.js查询中执行大于语法的操作

ton*_*jac 10 mongoose mongodb node.js

如何使用"大于"语法来处理此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');
Run Code Online (Sandbox Code Playgroud)

它不断崩溃我的节点服务器.

我想将此保留在对象语法中,而不是为了可读性而使用对象语法进行内联.我可以这样做:

where.scoreTotal = $gt(0);
Run Code Online (Sandbox Code Playgroud)

cod*_*Gig 19

您可以使用查询

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);
Run Code Online (Sandbox Code Playgroud)

或使用查询构建器

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);
Run Code Online (Sandbox Code Playgroud)


小智 8

有关详细说明和完整使用细则,请参阅官方文档:http://mongoosejs.com/docs/queries.html

而不是where.scoreTotal > 0
添加"where.scoreTotal" : { $gt : 0}