Skip to content Skip to sidebar Skip to footer

Mongoose - No Matching Document Found (foreach)

I'm new to NodeJS and Mongoose and this might be a duplicate question, so don't reply back negatively please. I tried finding a solution but failed to fix this error. Basically, I

Solution 1:

if break out of an iteration is your issue, then why not use a simple for loop with break statement.

let eduArray = doc.local.education;
for(i=0;i<eduArray.length;i++) {
   if(eduArray[i]["id"] == row_id) {
      // do your logic
      break;
   }
}

Solution 2:

becuase you are updating the education first time with no problem, then the problem appears afterwards, I suspect that you update the education wrongly, look into this line of code you wrote:

doc.local.education[index] = req.body;

here I see you are assigning whatever inside the request body to education, but have you checked what data is actually inside the req.body?

try to log the req.body to see what you actually assigning to the education.

Post a Comment for "Mongoose - No Matching Document Found (foreach)"