Am not able read blob (binary) record from MongoDB, am using Java 3.4.2 driver.
BasicDBObject whereClause = new BasicDBObject();
List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
obj.add(new BasicDBObject("blobcontentid", "20160601201035069394000000"));
whereClause.put("$and", obj);
MongoCursor<Document> cursor = contentcollection.find(whereClause).iterator();
while (cursor.hasNext()) {
Document object = cursor.next();
System.out.println(object.getString("blobcontentid"));
if (object.get("content") != null){
byte[] content = (byte []) object.get("content");
} else {
System.out.println("Content is empty");
}
}
Error: java.lang.ClassCastException: org.bson.types.Binary cannot be cast to [B
Same record am reading like this in DB2. byte[] content = aResult.getBytes("CONTENT");
Thank you in advance! Bharathi