title: What's the update equivalent of insertMany in Mongo / Java
body: <p>I am trying to do a bulk upsert, but am having problems to figure out how to do it. This does not work:</p>
  
  <pre><code>    BasicDBObject filter = new BasicDBObject();
      BasicDBObject update = new BasicDBObject("$set", list);
      UpdateOptions options = new UpdateOptions().upsert(true);
      collection.updateMany(filter, update, options);
  </code></pre>
  
  <p>Exception in thread "main" com.mongodb.MongoWriteException: Modifiers operate on fields but we found a Array instead.</p>
  
  <p>Any examples would just be great!</p>
  
  <h2>UpsertMany items in one roundtrip</h2>
  
  <p>This is what I meant:</p>
  
  <pre><code>public static BulkWriteResult upsertAll(MongoCollection&lt;Document&gt; coll, List&lt;Document&gt; docs, String keyTag) {
      List&lt;UpdateOneModel&lt;Document&gt;&gt; requests = new ArrayList&lt;UpdateOneModel&lt;Document&gt;&gt;();
      UpdateOptions opt = new UpdateOptions().upsert(true);
      for (Document doc : docs ) {
          BasicDBObject filter = new BasicDBObject(keyTag, doc.get(keyTag)); 
          BasicDBObject action = new BasicDBObject("$set", doc);
          requests.add(new UpdateOneModel&lt;Document&gt;(filter, action, opt));
      }
      return coll.bulkWrite(requests);
  }
  </code></pre>