MongoClient mongoClient = new MongoClient("192.168.128.145",27017); MongoDatabase db = mongoClient.getDatabase("test"); // Document document = new Document(); // InputStream is = new FileInputStream("d:\\cloud_sql.sql"); // byte [] bytes = IOUtils.toByteArray(is); // is.close(); // Binary bsonValue = new Binary(bytes); // document.put("img",bsonValue); // document.put("fileName","mysql"); // db.getCollection("mycoll").insertOne(document); // db.getCollection("mycoll").drop(); // FindIterable<Document> tDocuments = db.getCollection("mycoll").find(); FindIterable<Document> tDocuments = db.getCollection("mycoll").find(new Document("fileName", "mysql")); tDocuments.forEach(new Block<Document>() { public void apply(final Document document) { System.out.println(document); Binary bsonValue1= document.get("img",Binary.class); byte[] dd = bsonValue1.getData(); try { String t = new String(dd,"utf-8"); System.out.print(t); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }); }
MongoDB 存储二进制小文件
猜你喜欢
转载自gangling.iteye.com/blog/2343966
今日推荐
周排行