Answer the question
In order to leave comments, you need to log in
How do you save an array of documents?
It is necessary to push 20-30 documents at a time into the collection, according to the documentation I found insertMany in mongoose, and immediately ran into a problem because the array contains documents that are already in the collection, as a result it spits out a duplicate error and does not save anything.
In mongo, in the documentation, as I understand it, it is written that if you pass Coll.insertMany(arr, {ordered:false}, (e) =>......
it, then errors will be ignored, and records will be saved. I did not check the performance in mongodb, but when using this parameter, mongoose (4.7.6) spits out an error that callback is not a function, maybe they did not take into account the presence of this parameter in insertMany, which in turn makes this function simply useless for me. Or am I doing something wrong.
Help me find a way out of the situation, I really don’t want to add one document at a time in the cycle.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question