title: How to update a document in MongoDB using ObjectID in Java
body: <p>What I am trying to accomplish here is pretty simple. I am trying to update a single document in MongoDB collection. When I look up the document using any field, such as "name", the update query succeeds. Here is the query:</p>
  
  <pre><code>mongoDB.getCollection("restaurants").updateOne(
      new BasicDBObject("name", "Morris Park Bake Shop"),
      new BasicDBObject("$set", new BasicDBObject("zipcode", "10462"))
  );
  </code></pre>
  
  <p>If I try to lookup the document with the ObjectId, it never works as it doesn't match any document.</p>
  
  <pre><code>mongoDB.getCollection("restaurants").updateOne(
      new BasicDBObject("_id", "56110fe1f882142d842b2a63"),
      new BasicDBObject("$set", new BasicDBObject("zipcode", "10462"))
  );
  </code></pre>
  
  <p>Is it possible to make this query work with Object IDs?</p>
  
  <p>I agree that my question is a bit similar to <a href="https://stackoverflow.com/questions/9797935/how-to-query-documents-using-id-field-in-java-mongodb-driver">How to query documents using &quot;_id&quot; field in Java mongodb driver?</a> however I am not getting any errors while trying to update a document. It just doesn't match anything.</p>