title: mongodb - how to build a multi operator update statement with java driver?
body: <p>How do I execute different updates on different fields of a single document as a single operation using java driver?
  Suppose I have a document like this</p>
  
  <pre><code>{
     _id: ObjectId("1234567890")
     ...
     elements: String[],
     last_user: String,
     ...
  }
  </code></pre>
  
  <p>and I want to add a string to the <code>elements</code> array and update <code>last_user</code>. I can do it as</p>
  
  <pre><code>import static com.mongodb.client.model.Filters.*;
  import static com.mongodb.client.model.Updates.*;
  
  ...
  
  Bson filter = eq(DBCollection.ID_FIELD_NAME, new ObjectId("1234567890"));
  Bson addElement = push("elements", "a new string");
  Bson updateLastUser = set("last_user", "last user name");
  
  mycollection.updateOne(filter, addElement);
  mycollection.updateOne(filter, updateLastUser);
  </code></pre>
  
  <p>it works but those are two separate operations, and I don't actually like it at all. </p>
  
  <p>I saw <a href="https://stackoverflow.com/questions/9823140/multiple-mongo-update-operator-in-a-single-statement">in this question</a> that with the shell i can do it like this</p>
  
  <pre><code>db.mycollection.update({ "_id": "1234567890" }, 
     {
        "$push" : { "elements": "a new string" }, 
        "$set" : { "last_user": "last user name" }
     }
  );
  </code></pre>
  
  <p>but I have no idea how I can build that single update object containing both <code>$push</code> and <code>$set</code> with java driver . I'm quite sure it's pretty simple and stupid but I can't find a solution.</p>