title: Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to com.mongodb.BasicDBObject
body: <p>I am trying to retrieve one particular field(<code>"Versions.id"</code>) from mongo using java</p>
  
  <p>Mongo query - <code>db.getCollection('SettlementInstance').find({"_id.timeSlice" : [2018,1,1], "_id.type" : "TRANSMISSION"})</code></p>
  
  <p>This is the data stored in mongo collection. I want to retrieve  <code>"id" : "3d8a3b31-aaa0-4c2e-82b3-5eaaa80d80e1"</code> using java</p>
  
  <pre><code>   {
              "_id" : {
                  "timeSlice" : [ 
                      2018, 
                      1, 
                      1
                  ],
                  "type" : "TRANSMISSION",
                  "@objectName" : "SettlementInstance"
              },
              "Versions" : [ 
                  {
                      "id" : "3d8a3b31-aaa0-4c2e-82b3-5eaaa80d80e1",
                      "status" : "ACTIVE",
                      "version" : NumberLong(11447)
                  }
              ]
          }
  </code></pre>
  
  <p>The Java program I was trying to retrieve the "id" field under "Versions" object, my code gives an exception.</p>
  
  <pre><code>String feedName = "ServicePointInputAdapter";
              Mongo mongo = new Mongo(host);
              DB db = mongo.getDB(("dbname"));
              DBCollection collection = db.getCollection("SettlementInstance");
              BasicDBObject whereQuery = new BasicDBObject();
              whereQuery.put("_id.type", "TRANSMISSION");
              whereQuery.put("_id.timeSlice", Arrays.asList(2018,1,1));
              DBCursor cursor = collection.find(whereQuery);
              try {
                  while (cursor.hasNext()) {
                      DBObject Features = cursor.next();
                      BasicDBList features = (BasicDBList) Features.get("Versions");
                      BasicDBObject[] featuresArr = features.toArray(new BasicDBObject[0]);
                      for (BasicDBObject dbobj : featuresArr) {
          *****                BasicDBObject si_id = (BasicDBObject) dbobj.get("id"); ***** //Getting error in the line }
                  }
              } finally {
                  cursor.close();
              }
          }
      } 
  </code></pre>
  
  <p>Unfortunately I am getting exception such as - </p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to com.mongodb.BasicDBObject.
  </code></pre>
  
  <p>Could some one help me resolve the issue and retrieve the "Versions.id" field from the collection.</p>