Answer the question
In order to leave comments, you need to log in
Why can't I save the modified mongoose object?
const dbObjects = await Model.find({ b })
for (const obj of parsedObjects) {
const dbObject = dbObjects.find(elem => elem.id === obj.id)
if(!dbObject) {
//dbObjects.shift(obj)
} else if(!(dbObject.e.length === obj.e.length)){
dbObject.e = obj.e
console.log(dbObjects)
}
}
await dbObjects.save()
Answer the question
In order to leave comments, you need to log in
.find() will return an array even if there is only one document, and an empty array if none is found, and an array cannot be .save()
for (const obj of parsedObjects) {
const dbObject = dbObjects.find(elem => elem.id === obj.id)
.....
// а вот здесь наверно получится
await dbObject.save()
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question