i cant figure out how to get when i have to find the all records in the mongo db document and check a field which is true or false from each document inside collection
here i am first finding all user from user table after that taking the user ids and finding teir course registrations if the course registration is true then i have to increase cnt by one my question is how can i get the final cnt value outside of for loop
here i am first finding all user from user table after that taking the user ids and finding teir course registrations if the course registration is true then i have to increase cnt by one my question is how can i get the final cnt value outside of for loop
Code:
countuser(){
let cnt=0;
for(let i=0;i<users.length;i++)
{
this.course_reg.find({_id:userId[i]},function(error,coursereg){
if(coursereg.isCompleted==true)
{
// it will count the user who have isCompleted is true
cnt++;
}
})
}
Comment