I try to update on group members value for each group , and after that i want to return new groups updated .i do this by adding each group to result array i declared before .
but i always got the empty result in result array . Anyone know how i can to make execution sequentially,do not goes to return statement first
This is my code :
searchGroups: async (groupIdsList, accountId) => {
var result = [];
return Group.find({
_id: { $in: groupIdsList },
accountId: mongoose.Types.ObjectId(accountId),
}).then((groupList) => {
groupList.forEach(function (group) {
groupService
.getMembersUserDetails(
group.members,
mongoose.Types.ObjectId(accountId)
)
.then((members) => {
group.members = members;
result.push(group);
});
});
return result;
});
};