Answer the question
In order to leave comments, you need to log in
How to update updateMany using each object's own properties?
I work with Mongoose
There is a collection with documents of this type
Task: in each document from strokeNamesString to make strokeNamesArr using the operation
strokeNamesArr = strokeNamesString.split('\n').map(e => JSON.parse(e))
await Char.updateMany({},{strokeNamesArr: this.strokeNamesString.split('\n').map(e => JSON.parse(e))});
Answer the question
In order to leave comments, you need to log in
this.strokeNamesString
you have nothing to do with the model, but with the function in which you call await Char.updateMany.
You cannot use a JS function in update that will be applied to each record, instead you can use a pipeline, and some expression for $set, if there is the functionality you need.
https://docs.mongodb.com/manual/reference/method/d...
If not, then update one by one.
or via bulkWrite - prepare all the data at once and send it in a batch in one operation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question