title: How do I use insertMany with Mongoose when I have a big array of object?
body: <p>I'm trying to use the insertMany method, but without success... I read this stackoverflow <a href="https://stackoverflow.com/a/35174701/4275509">answer</a>, but it does not tell how to do handle array of objects that are very big.</p>
  
  <p>In my test case I have 9755 objects, with this script it imports all lines 9 times, which is not what I want...</p>
  
  <p>I would like to dive the array in chunks of 1000 objects for each import.</p>
  
  <p>How can I do this?</p>
  
  <pre><code>function bulkImportToMongo(arrayToImport, mongooseModel) {
    const Model = require(`../../../models/${mongooseModel}`);
    let counter = 0;
    let temp = [];
    arrayToImport.forEach(item =&gt; {
      temp.push(item);
      counter++;
  
      if (counter % 1000 == 0) {
        Model.insertMany(temp).then(mongoosedocs =&gt; {
          console.log(`imported ${counter} objects`);
          console.log(mongoosedocs.length);
          temp = [];
        });
      }
    });
  }
  </code></pre>