code: public WriteResult save(final DBObject document, final WriteConcern writeConcern) {
          Object id = document.get(ID_FIELD_NAME);
          if (id == null) {
              return insert(document, writeConcern);
          } else {
              return replaceOrInsert(document, id, writeConcern);
          }
      }
docs: Update an existing document or insert a document depending on the parameter. If the document does not contain an '_id' field, then
  the method performs an insert with the specified fields in the document as well as an '_id' field with a unique objectId value. If
  the document contains an '_id' field, then the method performs an upsert querying the collection on the '_id' field:
  <ul>
  <li>If a document does not exist with the specified '_id' value, the method performs an insert with the specified fields in
  the document.</li>
  <li>If a document exists with the specified '_id' value, the method performs an update,
  replacing all field in the existing record with the fields from the document.</li>
  </ul>
  
  @param document     {@link DBObject} to save to the collection.
  @param writeConcern {@code WriteConcern} to be used during operation
  @return the result of the operation
  @throws com.mongodb.DuplicateKeyException if the write failed to a duplicate unique key
  @throws com.mongodb.WriteConcernException if the write failed due some other failure specific to the insert or update command
  @throws MongoException if the operation failed for some other reason
  @mongodb.driver.manual tutorial/modify-documents/#modify-a-document-with-save-method Save