How to obtain successful ids from mongoose InsertMany

127 views
Skip to first unread message

dwak...@gmail.com

unread,
May 7, 2019, 1:22:03 PM5/7/19
to Mongoose Node.JS ODM
Im using insertMany to batchInsert from a CSV. The main problem im getting is that when it fails due to unique index, it does not discriminate (or at least i can find it) from failed ids and actually inserted. There is a list of "insertedIds" but it lists all ids. 

Is this a feature or am i doing something wrong?
Is there a workaround?


I have already tried changing the options using 

{ordered:false, rawResult: false}


Its actually nothing very fancy, just a simple insertMany, but it will fail (im counting on it) with duplicate index.

 this.insertMany(chunck, {ordered:false, rawResult: false}, ( err, docs ) => {
 if (err) {
   console.log(err.result);
 }
 else {
   console.log(docs);
 }



Thanks!
Reply all
Reply to author
Forward
0 new messages