Javascript express.js中的查询$or
如何在express.js app.get()函数中查询$or? 对于本例中的find()查询Javascript express.js中的查询$or,javascript,node.js,mongodb,express,Javascript,Node.js,Mongodb,Express,如何在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
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
});
参考:
在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);
});
});
我很困惑,route param:collection在您的soln中扮演什么角色。在我的回答中,collection是通过mongoose DB连接API获得的