I have a route which performs 2 queries in 2 different databases like so:
app.post('/location',function(req,res){
Db.find({id:anId},function(err,doc){
myDocs=[]
for (var i = doc.length - 1; i >= 0; i--) {
myDocs.push(doc[i])
otherDocs=[]
otherDb.find({id:doc[i].id},function(err,doc2){
for (var i = doc2.length - 1; i >= 0; i--) {
otherDocs.push(doc2[i])
}
})
myDocs.push(otherDocs)
}
res.send(myDocs)
})
})
The issue here is that otherDocs
is local to the anonymous function in otherDb
, I am not able to access it from outside and push it into myDocs
. How would I be able to do this?