Q:

nodejs mongodb driver native query issue

It turns a funny error in Node.js mongodb, if I put the form below:
locals.collection.find(filter, req.query);

returns me the following error:
MongoError: query selector must be an object

Now if I manually put the query works.
I'm having this problem a long time, and I've tried several ways.
locals.collection.find({slug:'somak'}, req.query);

I am using the following function:
exports.findAll = function(req, res, next) {

    var locals  = {},
        section = req.params.section,
        query   = req.query,
        filter  = {};

    if(query.filter) {

        filter = query.filter.replace(/"(\w+)"\s*:/g, '$1:');
        filter = filter.replace(/["]/g, "'");

    }

    console.log(filter);

    delete query.filter;

    async.series([

        function(callback) {
            MongoClient.connect(url, function(err, db) {
                if (err) return callback(err);
                locals.collection = db.collection(section);
                callback();
            });
        },

        function(callback) {
            locals.collection.count(filter, function (err, result){
                if (err) return callback(err);
                locals.count = result;
                callback();
            });
        },

        function(callback) {

            var cursor = locals.collection.find({slug:'somak'}, req.query);

            if(req.query.page) {
                cursor = cursor.skip(Math.abs(req.query.limit) * --req.query.page);
            }

            cursor.toArray(function(err, docs) {
                if (err) return callback(err);
                locals.docs = docs;
                callback();
            });
        }
    ],

    function(err) { //This function gets called after the three tasks have called their "task callbacks"
        if (err) return next(err);
        // Here locals will be populated with 'count' and 'docs'
        res.json({
            count: locals.count,
            data: locals.docs
        });
    });

A:

Just use JSON.parse:
exports.findAll = function(req, res, next) {

    var locals  = {},
        section = req.params.section,
        query   = req.query,
        filter  = {};

    if(query.filter) {
        filter = JSON.parse(query.filter);
    }

    delete query.filter;

...

