title: MongoDB 3.6-4.0 bulk-insert limitations
body: <p>According to official <a href="https://docs.mongodb.com/manual/reference/limits/" rel="nofollow noreferrer">MongoDB documentation</a>, since version 3.6 the limit for a bulk-insert is 100,000 operations (compared to 1000 operations in older versions).</p>
  
  <p>As a benchmark, using the Java client I insert 100K documents to a collection in varying bulk sizes from 1 to 100K inserts. These are the results of some configurations:</p>
  
  <p><a href="https://i.stack.imgur.com/cawYZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cawYZ.png" alt="enter image description here"></a></p>
  
  <p>I see that version 3.2, like version 3.6 gives the same results for bulks larger than 500-1000 ops. </p>
  
  <p>Some info about the setup of the last benchmark:</p>
  
  <ul>
  <li>6 Virtual CPU</li>
  <li>Windows Server 2012</li>
  <li>128GB RAM</li>
  <li>MongoDB version 3.6, running <code>mongod</code></li>
  <li>wiredTigerCacheSizeGB = 20</li>
  <li>Inserted document has 5 fields: <code>fName</code>, <code>lName</code>, <code>text1</code>, <code>text2</code> and <code>text3</code>. The later 3 fields contain a similar paragraph of "Lorem ipsum".</li>
  <li>Java mongoDB client: <code>org.mongodb.mongo-java-driver</code> version <code>3.8.0</code></li>
  </ul>
  
  <p>This is the code of the benchmark:</p>
  
  <pre><code>    public static void main(String[] args) {
  
  
          MongoCredential credential = MongoCredential.createCredential("user", "admin", "password".toCharArray());
          MongoClient mongoClient = new MongoClient(new ServerAddress("localhost", 27017), Arrays.asList(credential));
          MongoDatabase db = mongoClient.getDatabase( "bulktest" );
  
          MongoCollection&lt;Document&gt; col = db.getCollection("test1");
  
          List&lt;InsertOneModel&lt;Document&gt;&gt; content;
  
          // iterating on different bulk sizes
          for (int size:TEST_SIZES){
              long total = 0;
  
              // doing each test a few times to get a more stable average
              for (int a = 0; a &lt; AVG_FACTOR; a++) {
  
                  // creating the 100K documents for insert BEFORE the benchmark, so that we won't deal with document creation as a part of the test
                  content = new ArrayList&lt;&gt;();
                  for (int d = 0; d &lt; DOC_COUNT; d++) {
                      content.add(new InsertOneModel&lt;&gt;(createSampleDocument()));
                  }
                  Iterator&lt;InsertOneModel&lt;Document&gt;&gt; iterator = content.iterator();
  
                  // each 'testBulkWrite' returns total insert time of 100K documents in the bulk size as passed in the parameter. We sum these times.
                  total += testBulkWrite(col, size, iterator);
              }
  
              System.out.println(String.format("%d", total / AVG_FACTOR));
  
          }
      }
  
      private static long testBulkWrite(MongoCollection&lt;Document&gt; col, int bulkSize, Iterator&lt;InsertOneModel&lt;Document&gt;&gt; iterator) {
          long start = System.currentTimeMillis();
  
          for (int i = 0; i &lt; DOC_COUNT; ){
              ArrayList&lt;InsertOneModel&lt;Document&gt;&gt; bulk = new ArrayList&lt;&gt;();
  
              for(int j = 0; j &lt; bulkSize &amp;&amp; i &lt; DOC_COUNT; j++,i++){
                  bulk.add(iterator.next());
              }
  
              col.bulkWrite(bulk, new BulkWriteOptions().ordered(false));
          }
          return (System.currentTimeMillis() - start);
      }
  
      private static Document createSampleDocument(){
          Document doc = new Document();
          doc.append("fname", "My");
          doc.append("lname", "Name");
          for (int i = 0; i &lt; 3; i++){
              doc.append("text" + i, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
          }
          return doc;
      }
  </code></pre>
  
  <p>Is there any other inherent bottleneck? What so I miss?</p>
  
  <p>Thanks</p>