array in node.js

39 views
Skip to first unread message

Hemanth kumar

unread,
May 5, 2016, 9:43:38 PM5/5/16
to nodejs
I am getting array from angular controller like [ '572b2e5d63f338b02afa36b9', '572b3da2034e6370301943bc' ] to node. 

Below code is my node

router.get('/purchaserInfo',function(req,res){
console.log(req.query.proID);
var productId = req.query.proID;
var findPurchaserInfo = function(db, callback) {
var cursor =db.collection('purchased').find({purchasedItemID:productId}).toArray(function(err, docs){
if(err){  
callback(new Error("Some problem"));
}else{
callback(null,docs);
});
};
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
findPurchaserInfo(db, function(err,docs) {
db.close();
if(err) return res.json({result:null})
else
return res.json({result: docs});
});
});
});



I want both product id to search but it takes only last one.How to solve this.

Alex Wells

unread,
May 6, 2016, 1:43:15 PM5/6/16
to nodejs
http://stackoverflow.com/questions/8303900/mongodb-mongoose-findmany-find-all-documents-with-ids-listed-in-array

Borrowing from a quick google, insert the '$in' clause:

    find('purchasedItemID': { $in: productId})
Reply all
Reply to author
Forward
0 new messages