Friday, 16 August 2013

async.parallel on mongodb and Node.js

async.parallel on mongodb and Node.js

In the following code:
var collection = db.collection('colname');
async.parallel([
function(callback(){collection.find({category:'a'}).sort({rank:1}).toArray(callback)},
function(callback(){collection.find({category:'b'}).sort({rank:1}).toArray(callback)}
], function(err, result){
if (err) throw err;
console.log('a');
concole.log(result);
console.log('b');
});
If I run the above code, which is inside MongoClient.connect function by
the way, I got a on the screen but didn't get b. So it looks like
console.log(result) stops running the code. How can I fix it and run the
query in parallel?
Thanks.

No comments:

Post a Comment