如何使用Node.js在MongoDB中进行类似的查询?
这是我的源代码,但它不起作用:
exports.findAll = function(req, res) {
var country=req.params.country;
db.collection('wines', function(err, collection) {
collection.find({ 'country': new RegExp('/'+country+'/i') }).toArray(function(err, items) {
res.jsonp(items);
});
});
};
Run Code Online (Sandbox Code Playgroud)
Ale*_*los 13
我这样解决了:
exports.findAll = function(req, res) {
var country=req.params.country;
db.collection('wines', function(err, collection) {
collection.find({ 'country': new RegExp(country, 'i') }).toArray(function(err, items) {
res.jsonp(items);
});
});
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7420 次 |
| 最近记录: |