I created a model from a schema which has a unique index.
I tried to use Model.collection.insert() to insert multiple documents.
The data may have some duplicate documents, so I used continueOnError in option.
I checked the shell, the data seems to be inserted normally, but in the callback, the documents passed is null.
Model.collection.insert(data.slice(0, 3), {
continueOnError: 1
}, function(err, documents) {
console.log(arguments); // { 0: null, 1: [{...}, {...}, {...}] }
});
then
Model.collection.insert(data.slice(0, 5), {
continueOnError: 1
}, function(err, documents) {
console.log(arguments); // { 0: error message, 1: null }
});
I just want to know how many documents I have insert successfully. How can I do that?