I simplified the problem as I could.
Transaction.find({budget: foundBudget._id}, function(err, foundTrans) {
if (err) console.log(err);
else {
uniqueUsers = foundTrans
.map(user => user.who)
.filter((value, index, self) => self.indexOf(value) === index)
console.log(uniqueUsers);
uniqueUsers.forEach(function(user, i) {
console.log("foundBudget._id " + foundBudget.id);
console.log("user " + user);
Transaction.find({budget: foundBudget._id, who: user}, 'amount')
.exec(function(err, amountsInTrans) {
if (err) console.log(err);
else console.log("Here");
});
});
console.log("Here2");
}
});
It won't go into the second Transaction.find() query's callback function.
console.log(uniqueUsers); logs [ 'Aras' ], simply because that's the only user.
console.log("foundBudget._id " + foundBudget.id); and console.log("user " + user); logs
foundBudget._id 5f77b8971fd44e456c8145d7
user Aras
and the related schema is like this,
const transactionSchema = new mongoose.Schema({
who: String,
amount: Number,
info: String,
budget: String
})
So, the query should work and it should go into the callback function but I'm not getting a log from console.log("Here");, I'm only getting Here2.
Any ideas?