How to get result from passing array in mongodb?
<p>I have an array, using this I want to search some products. The array shown below.</p>

<pre><code> "productIds": [
   {
     "productId": ObjectId("574592dfc07f13943255c19d") 
   },
   {
     "productId": ObjectId("5745934cc07f13943255c19f") 
   },
   {
     "productId": ObjectId("57459397c07f13943255c1a1") 
   } 
 ] 
</code></pre>

<p>using this <code>productId</code> I want to search particular products. I have written some query but it takes only first <code>productId</code> and it's not taking remaining.</p>

<pre><code>router.post('/getItemOfWishList', function(req,res){
    var wId = ObjectId(req.body.wID);
    var findwishlists = function(db, callback) {
        var cursor =db.collection('wishlists').find({_id: wId}).toArray(function(err, docs){
            if(err){  
                callback(new Error("Some problem"));
            }else{
                callback(null,docs);
            } 
        });
    };

    MongoClient.connect(config.database, function(err, db) {
        assert.equal(null, err);
        findwishlists(db, function(err,docs) {
            db.close();

            //console.log(docs[0].productIds);//It contains that array.


            for(var key in docs){
                console.log(docs[key].productIds[key].productId);
                var pID = ObjectId(docs[key].productIds[key].productId);

                var findproducts = function(db, callback) {
                    var cursor =db.collection('proInfo').find({_id: pID}).toArray(function(err, docs){
                        if(err){  
                            callback(new Error("Some problem"));
                        }else{
                            callback(null,docs);
                        } 
                    });
                };

                MongoClient.connect(config.database, function(err, db) {
                    assert.equal(null, err);
                    findproducts(db, function(err,docs) {
                        db.close();
                        if(err) return res.json({result:null})
                        else
                        return res.json({result: docs});
                    });
                });                 
            }
        });
    });
});
</code></pre>