从Node.js中查询MongoDB中的like

Ale*_*los 4 mongodb node.js

如何使用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)