在快递.js中查询$or

Query $or in express.js

本文关键字:or 查询 快递 js      更新时间:2023-09-26

如何在 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/

在快递之上使用猫鼬蒙戈驱动程序,您可以做到这一点,

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);
    });
});