{"action":"created","issue":{"url":"https://api.github.com/repos/fakemongo/fongo/issues/202","repository_url":"https://api.github.com/repos/fakemongo/fongo","labels_url":"https://api.github.com/repos/fakemongo/fongo/issues/202/labels{/name}","comments_url":"https://api.github.com/repos/fakemongo/fongo/issues/202/comments","events_url":"https://api.github.com/repos/fakemongo/fongo/issues/202/events","html_url":"https://github.com/fakemongo/fongo/issues/202","id":147412258,"number":202,"title":"Aggregation using Cursor causing org.bson.Document cannot be cast to com.mongodb.DBObject","user":{"login":"tejkumar51","id":9503227,"avatar_url":"https://avatars.githubusercontent.com/u/9503227?v=3","gravatar_id":"","url":"https://api.github.com/users/tejkumar51","html_url":"https://github.com/tejkumar51","followers_url":"https://api.github.com/users/tejkumar51/followers","following_url":"https://api.github.com/users/tejkumar51/following{/other_user}","gists_url":"https://api.github.com/users/tejkumar51/gists{/gist_id}","starred_url":"https://api.github.com/users/tejkumar51/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejkumar51/subscriptions","organizations_url":"https://api.github.com/users/tejkumar51/orgs","repos_url":"https://api.github.com/users/tejkumar51/repos","events_url":"https://api.github.com/users/tejkumar51/events{/privacy}","received_events_url":"https://api.github.com/users/tejkumar51/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-11T12:31:35Z","updated_at":"2016-04-19T18:44:41Z","closed_at":null,"body":"After aggregating using dbcursor in Fakemongo, unable to get DBObjects from cursor (**cursor.next()**)\r\nThrowing the class cast exception \r\n(Working fine when tested with mongo)\r\n\r\n## Exception:\r\n```\r\nCaused by: java.lang.ClassCastException: org.bson.Document cannot be cast to com.mongodb.DBObject\r\n\tat com.mongodb.MongoCursorAdapter.next(MongoCursorAdapter.java:51)\r\n\tat com.mongodb.MongoCursorAdapter.next(MongoCursorAdapter.java:22)\r\n```\r\n\r\n## Example Code snippet: \r\n_______________\r\n```\r\ncom.mongodb.AggregationOptions options = com.mongodb.AggregationOptions.builder()\r\n\t\t\t\t.outputMode(com.mongodb.AggregationOptions.OutputMode.CURSOR).batchSize(Integer.valueOf(batchSize))\r\n\t\t\t\t.allowDiskUse(true).build();\r\n\t\tDBCollection collection = mongoDbFactory.getDb().getCollection(INVENTORY_BALANCE_ANNUAL);\r\n\r\n\t\tList<DBObject> pipeline = new ArrayList<DBObject>(preparePipeline(transactionNumber));\r\n\t\tCursor cursor = collection.aggregate(pipeline, options);\r\n```\r\n______________\r\n```\r\ntry {\r\n\t\t\twhile (cursor.hasNext()) {\r\n\t\t\t\tDBObject inventoryBalanceDbObject = cursor.next();\r\n\t\t\t\tinventoryBalanceFileWriter.writeEDIRecordToFile(\r\n\t\t\t\t\t\tbuildInventoryBalanceAnnualEDIRecord(inventoryBalanceDbObject), bufferedWriter);\r\n\t\t\t}\r\n\t\t} catch (Exception e) {\r\n\t\t\tthrow new InventoryBalanceException(EDI_BUILDING_EXCEPTION_MESSAGE, e);\r\n\t\t} finally {\r\n\t\t\tcursor.close();\r\n\t\t}\r\n```\r\n____________________________\r\n\r\nAny idea ?"},"comment":{"url":"https://api.github.com/repos/fakemongo/fongo/issues/comments/212064369","html_url":"https://github.com/fakemongo/fongo/issues/202#issuecomment-212064369","issue_url":"https://api.github.com/repos/fakemongo/fongo/issues/202","id":212064369,"user":{"login":"twillouer","id":2970220,"avatar_url":"https://avatars.githubusercontent.com/u/2970220?v=3","gravatar_id":"","url":"https://api.github.com/users/twillouer","html_url":"https://github.com/twillouer","followers_url":"https://api.github.com/users/twillouer/followers","following_url":"https://api.github.com/users/twillouer/following{/other_user}","gists_url":"https://api.github.com/users/twillouer/gists{/gist_id}","starred_url":"https://api.github.com/users/twillouer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twillouer/subscriptions","organizations_url":"https://api.github.com/users/twillouer/orgs","repos_url":"https://api.github.com/users/twillouer/repos","events_url":"https://api.github.com/users/twillouer/events{/privacy}","received_events_url":"https://api.github.com/users/twillouer/received_events","type":"User","site_admin":false},"created_at":"2016-04-19T18:44:41Z","updated_at":"2016-04-19T18:44:41Z","body":"Yes, can you try against the v3 branch ?"}}