title: Spark Mongo connector: Upsert only one attribute in MongoDB connection
body: <p>Let's say I have the following Mongo document:</p>
  
  <pre><code>{
   "_id":1, 
   "age": 10,
   "foo": 20
  }
  </code></pre>
  
  <p>and the following Spark DataFrame <code>df</code>: </p>
  
  <pre><code>_id | val
   1  | 'a'
   2  | 'b'
  </code></pre>
  
  <p>and now I want to append the <code>val</code> from the dataframe to the Mongo document... </p>
  
  <p>Using the <a href="https://docs.mongodb.com/spark-connector/master/" rel="nofollow noreferrer">MongoDB Spark connector</a>, I can use the <em>default upserting</em> logic via "_id" append, meaning if the "_id" in Spark dataframe and Mongo document matches, Mongo connector will not create a new document, but rather update the old one. </p>
  
  <p>But! The update basically behaves like <em>replace</em> - if I do the following:</p>
  
  <pre><code>df
  .write.format("com.mongodb.spark.sql.DefaultSource")
  .mode("append")
  .option('spark.mongodb.output.uri','mongodb://mongo_server:27017/testdb.test_collection')
  .save()
  </code></pre>
  
  <p>The collection will look like:</p>
  
  <pre><code>[   
      {
       "_id":1, 
       "val": 'a'
      },
     {
       "_id":2, 
       "val':'b' 
      }
  ]
  </code></pre>
  
  <p>and I would like to obtain this:</p>
  
  <pre><code>[   
      {
       "_id":1, 
       "age": 10,
       "foo": 20
       "val": 'a'
      },
     {
       "_id":2, 
       "val':'b' 
      }
  ]
  </code></pre>
  
  <hr>
  
  <p><strong>My questions are</strong>: </p>
  
  <ul>
  <li><p>is there way (some option) to make the Spark connector behave the way
  I want it to behave?  </p></li>
  <li><p>Sure, I can first read the documents from Mongo to Spark, enrich
  them with the "val" attribute and write/append it back to the Mongo. What is I/O of this operation? Is it a full load (reading all documents and then
  replacing all attributes) or is it somewhat clever (like reading all
  documents but appending only the "val" attribute, not
  replacing the entire document)?</p></li>
  </ul>