简体   繁体   中英

How to use arrays in mongodb query inside node.js?

ExtJs Code:

tab.getStore().getProxy().setExtraParam("CCP", filterDetails );
                tab.getStore().load();

Node.js Code:

exports.loadGrid = function(req, res){
    var filteredDetails = req.param('CCP');
    console.log(filteredDetails );
    mongoClient.connect(config.database.path, function(err, db) {
        if(err) throw err;
        var collection = db.collection('trades');
        // Locate all the entries using find
        if(filteredDetails != null)
        {
            collection.find({$and:[ filteredDetails ]}).toArray(function(err, results) {
                console.log(results);
                res.send(results);
                db.close();
            });
        }
        else
        {
            collection.find().toArray(function(err, results) {
                console.log(results);
                res.send(results);
                db.close();
            });
        }
    })
};

Here is my result:

[ '[object Object]', '[object Object]' ]

This is the log printed in the console for the code[console.log(filteredDetails );]. Here i want values instead of object.

You might also try util.inspect to inspect your array of objects.

var util = require('util');

console.log(util.inspect(filteredDetails, { showHidden: true, depth: null }));

Util is one of node's core modules. You can find more information on it here: http://nodejs.org/api/util.html#util_util_inspect_object_options

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM