title: Conversion from String to MongoDB ObjectID
body: <p>I tried converting my String ID to MongoDB ObjectID</p>
  
  <pre><code>public class relevancy_test extends  Object implements Comparable&lt;ObjectId&gt; {
      public static void main(String[] args) throws UnknownHostException {
          MongoClient mongo = new MongoClient("localhost", 27017);
          DB mydb = mongo.getDB("test");
          DBCollection mycoll = mydb.getCollection("mytempcoll");
          BasicDBObject query = null;
          Map&lt;ObjectId, DBObject&gt; updateMap = new HashMap&lt;ObjectId, DBObject&gt;();
          List&lt;DBObject&gt; dbobj = null;
          DBCursor cursor = mycoll.find();
          dbobj = cursor.toArray();
  
          for (DBObject postObj : dbobj) {
              String id = postObj.get("_id").toString();
              ObjectId objId = new ObjectId((String) postObj.get("_id"));
              updateMap.put(objId, postObj);
          }
      }
  }
  </code></pre>
  
  <p>Here <code>(String) postObj.get("_id")</code> is of form <code>"8001_469437317594492928_1400737805000"</code></p>
  
  <p>On running following error shows up</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: invalid ObjectId [8001_469437317594492928_1400737805000]
      at org.bson.types.ObjectId.&lt;init&gt;(ObjectId.java:181)
      at org.bson.types.ObjectId.&lt;init&gt;(ObjectId.java:167)
      at fetch_data_tanmay.relevancy_test.main(relevancy_test.java:48)
  </code></pre>