Skip to content

Instantly share code, notes, and snippets.

@mrsid96
Created March 30, 2019 03:26
Show Gist options
  • Save mrsid96/4cd04f87b7c850b840618a9f9f481929 to your computer and use it in GitHub Desktop.
Save mrsid96/4cd04f87b7c850b840618a9f9f481929 to your computer and use it in GitHub Desktop.
async.map
async function asyncFunction(name) {
await collection.find({
"name": new RegExp(name, 'i')
}, (err, res) => {
if(err)
console.log("Error:",err);
else {
async.map(res, (item, callback)=>{
anotherCollection.findById(item.id, (err, res)=>{
if(err)
return callback(err);
else{
let toRet={};
// Add Business Logic
return callback(null, toRet);
}
})
}, (err, res)=>{
if(err)
console.log("Error:",err);
else
console.log("Success:",res);;
})
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment