Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have put code to create a mongoose document on mongo atlas inside a promise, which gets added 5214 times ("in promise" counter). However, the code after the call ("in create response:" counter) to create the mongoose object only gets run 206 times once I run promise.allSettled at the end. I don't know what's wrong. Thank you so much for your help!


for (var db of databases){
    
          var myFunction = new Promise(function(resolve, reject) {  
            myPromiseCounter++;
            console.log("in promise: " + myPromiseCounter) 
         
      Item.create({
          retailer:db.retailer,
          lastupdated:db.lastUpdated,
          retailerproductid:db.retailerProductId,
          categoryhierarchy:db.categoryHierarchy,
          title: db.title,
          description: db.desc, 
          color: db.color,
          typeclothing:myTest, 
          clothingkeywords:[],
          size: db.size,
          brand: db.brand,
          gender: db.gender=="male" ? 0 : 1,//0 Male, 1 Female
          price: db.retailPrice,
          images: db.images, 
          url: db.url, 
          relatedproducts:JSON.stringify(db.relatedProducts)
        }).then( (response) => {
          myCreateCounter++;
        console.log("in create response: " + myCreateCounter)


What I have tried:

I have put code to create a mongoose document on mongo atlas inside a promise, which gets added 5214 times ("in promise" counter). However, the code after the call ("in create response:" counter) to create the mongoose object only gets run 206 times once I run promise.allSettled at the end. I don't know what's wrong. Thank you so much for your help!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900