Created
March 30, 2019 03:26
-
-
Save mrsid96/4cd04f87b7c850b840618a9f9f481929 to your computer and use it in GitHub Desktop.
async.map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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