title: What are the ways to use MongoTemplate optimized for performance?
body: <p>I noticed that batch insert using <code>MongoTemplate.insert(Collection&lt;?&gt; …)</code> method is much slower than using MongoDB Java driver.</p>
  
  <p>As far as I understand it, the differences comes from the fact that the MongoTemplate is performing some serial operations and I'm talking about the next lines of code :</p>
  
  <pre><code>for (T o : batchToSave) {
  
    initializeVersionProperty(o);
    BasicDBObject dbDoc = new BasicDBObject();
  
    maybeEmitEvent(new BeforeConvertEvent&lt;T&gt;(o));
    writer.write(o, dbDoc);
  
    maybeEmitEvent(new BeforeSaveEvent&lt;T&gt;(o, dbDoc));
    dbObjectList.add(dbDoc);
  }
  </code></pre>
  
  <p>And :</p>
  
  <pre><code>for (T obj : batchToSave) {
    if (i &lt; ids.size()) {
      populateIdIfNecessary(obj, ids.get(i));
      maybeEmitEvent(new AfterSaveEvent&lt;T&gt;(obj, dbObjectList.get(i)));
    }
    i++;
  }
  </code></pre>
  
  <p>Now, is there a way to configure <code>MongoTemplate</code> to a void those heavy time consuming operations, maybe not publishing events or something?</p>