繁体   English   中英

在express.js中查询$ or

[英]Query $or in express.js

如何在express.js app.get()函数中查询$ or? 对于本例中的find()查询,

db.inventory.find( { $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] } )

我想知道如何转换为app.get()函数格式:

app.get('/:collection', function(req,res){
 var collection = db.get(req.param.collection);
 collection.find({}) // Query Part

});

参考: http : //docs.mongodb.org/manual/reference/operator/query/or/

借助express上的mongoose mongo驱动程序,您可以执行此操作,

app.get('/:collection', function(req,res){
  //var collection = db.get(req.param.collection);
  Collection.find( { $or:[ {'quantity':{ $lt: 20 }}, { price: 10 } ]}, 
      function(err,docs){
        if(!err) res.send(docs);
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM