class="java" name="code"> Document doc2 = new Document(); doc2.append("$set",doc); collection.updateOne(filter, doc2,new UpdateOptions().upsert(true));