title: mongodb insert document with just id, or do nothing
body: <p>I have a database of web domains, where the data is like this:</p>
  
  <pre><code>{"_id": "es.wikipedia.org"}
  {"_id": "en.wikipedia.org"}
  </code></pre>
  
  <p>And I want to (try to) insert domains which may already be in the collection like "stackoverflow.com" or "es.wikipedia.org", so if the document is not in the database, insert it, but if it is, then just skip and do nothing. But I cannot do it in one operation. If I go with </p>
  
  <pre><code> collection.insert(new Document("_id", "es.wikipedia.org"));
  </code></pre>
  
  <p>it fails with an exception if the document already exists in the collection. And if I try to go with an update, like this:</p>
  
  <pre><code> collection.updateOne(new Document("_id", "es.wikipedia.org"), new Document("$set", new Document()), new UpdateOptions().upsert(true));
  </code></pre>
  
  <p>it fails because the <code>$set</code> field is empty. But it is just a list, it does not have (at the moment) any more fields than "_id". Is there a way to do this? Am I making a mistake?</p>