I'm facing this nested resource access to mongodb in Node.JS
I need to access to resources (let's call "resource_a") and their related sub-resources of the "resource_a" (let's call "resource_b"). I have a set of resource_b for each resource_a.
The code above is not working since it calls the callback on the first iteration. What is the best choice to get callback called as soon as all the resourceB calls are solved? Thanks, franco
function someFunction(err, callback){
resourceA.find({}, function(err, resources_a){
for(var resource in resources_a) {
resourceB.find({"resourceA_Id":resources[resource]._id}, function(err, resources_b){
// here some operation
callback(null, {"result":"..."}
}
});
}