473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to get data from mongoose find query inside for loop

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
Expand|Select|Wrap|Line Numbers
  1.        countuser(){
  2.        let cnt=0;
  3.        for(let i=0;i<users.length;i++)
  4.         {
  5.            this.course_reg.find({_id:userId[i]},function(error,coursereg){
  6.  
  7.                       if(coursereg.isCompleted==true)
  8.                        {
  9.                                  // it will count the user who have isCompleted is true
  10.                                     cnt++;
  11.                         }
  12.            })
  13. }
  14.  
Oct 16 '22 #1
1 10955
zmbd
5,501 Expert Mod 4TB
the variable cnt should have your loop count, no?
However, you don't mention what you want to do with the value; thus, something simple like console.log(cnt) should send the value to the console
Oct 22 '22 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform'...
2
by: KnightWolfJK | last post by:
I'm working with a form and need some help customizing the results of a find query. I dug thru the archives and used this post...
1
by: chris.thompson13 | last post by:
Any relevant advice would be most appreciated for the following problem I have. I have a query that draws its data from 7 other queries. I would like to be able to edit data through that query....
5
by: BlackIce | last post by:
I want to query one table and get back two simple sets of data with one query. I have a table with date start, date ended, scheduled/unscheduled. I want to be able to get all of the dates within...
3
by: tmthomp3 | last post by:
i am trying to write a program but it is not working the way it should? can you find the infinite loop... #include <iostream> using namespace std; int main() {
2
ebs57
by: ebs57 | last post by:
Would the experts please indicate how to pass unbound control data to a query? When I pass a bound field from a combo box to my select query, everything is fine; when I change the combo box to an...
3
by: robin1983 | last post by:
HI all, how are you ? i need help from you people. This time my problem is that i m running a query inside another query. But, the result that i got is something not exactly what i want. and one...
2
by: vaneetnagpal | last post by:
I have a develop a mini program, when i save the data in msaccess databace, i give the find query code, this didn't work , how can i solve the proble, give me sample code of ind query Vaneet...
1
by: maryanncanor | last post by:
Hi I would like to know if there is a macro that can export the data from a query to an output textfile that has NO QUOTES. If I run the concatenated query Expr1: & & & & & & & ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.