Struggling with using async in conjunction with mongoose. Here's my code snippet :
function() {
SchemaOne.findById(fooIdOne).exec().then( x => {
// Some initial instructions
myCollection.foreach( y => {
SchemaTwo.findById(fooIdTwo).exec().then( z => {
// Additional instructions
});
});
}).then(() => {
// Code to run afterwards
});
}
Desiring the "initial instructions" and "additional instructions" to be completed BEFORE the "code to execute after", but the final "then" does not seem to wait for the additional instructions.
Assistance would be greatly appreciated! Thank you, Kev'.