473,657 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get data from mongoose find query inside for loop

1 New Member
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 11037
zmbd
5,501 Recognized Expert Moderator Expert
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
8438
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' action='ins_op.php' method='post'>"; lots of form stuff
2
1825
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 (http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=t1Xn2.443%24Qo5.1313%40nnrp2.clara.net) to help with a find query that would launch the Find box (aka Ctrl+F). Here's the problem: When the Find box launches, the "Look In" field is set to "title" by default. To successfully find any data, one...
1
5192
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. Is it possible or am I trying to do something impossible? Thanks in advance. Chris.
5
1765
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 a particular month and separate them out but scheduled or unscheduled. so the result of the query would look like Scheduled Unscheduled June 5 7 July 2 1 August ...
3
2385
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
3838
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 unbound box (so that the underlying table is not updated with a new record) the query receives an empty string. Incidentally, is there a wizard in ACC2003 for creating a query using a control from a form? That would be delicious.
3
2062
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 problem its only showing the result that is affected by the inside query. syntaxt is some thing like this $sql = "run some query"; $result = mysql_query($sql); while($rows= mysql_fetch_array($result)) { // inside query i access one field...
2
1090
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 Nagpal M-919876417074
1
4130
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: & & & & & & & and export it in Export Text wizard as text, with delimited, Other: | (pipeline) and Text qualifier as none>next>finish I can get the desired output without quotes. But this is a very long process for a user.
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.