查询$或在express.js中

时间:2015-01-14 05:26:58

标签: javascript node.js mongodb express

如何查询$或express.js app.get()函数? 对于此示例中的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/

1 个答案:

答案 0 :(得分:0)

使用mongoose mongo驱动程序在express之上,你可以这样做,

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);
    });
});
相关问题