title: Copy (update if exists) document from one collection to another
body: <p>I want to copy a document from one collection of mongodb to another collection (or update if exist) through java.</p>
  
  <p>I don't want to append each field of existing collection and then insert to another. How can I do this?</p>
  
  <p>Here are two collections, <code>temp</code> and <code>national</code>. <code>temp</code> has only one collection, which I have to copy to <code>national</code> or update if it exists.</p>
  
  <pre><code>MongoCursor&lt;Document&gt; cursor = db.getCollection("temp").find().iterator();
  try {
      Document doc = new Document(cursor.next());
      Document new_doc = new Document("$set",doc);
      doc.append("booking_id",cursor.next().get("booking_id"));
      MongoCursor&lt;Document&gt;  cursor1 = db.getCollection("national").find(doc).iterator();
      Bson filter = Filters.eq("booking_id", args);
      Bson update = Filters.elemMatch("booking_id", filter);
      UpdateOptions options = new UpdateOptions().upsert(true);
      national.updateOne(filter, new_doc, options);
  }
  finally {
      cursor.close();
  }
  </code></pre>