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,
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!