MongoDB
 sql >> Base de données >  >> NoSQL >> MongoDB

GridFSDBFile dans la version Spring Boot 2.0.1

GridFSFile gridFsdbFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(id)));

GridFSDownloadStream gridFSDownloadStream = gridFSBucket.openDownloadStream(gridFsdbFile.getObjectId());
GridFsResource gridFsResource = new GridFsResource(gridFsdbFile,gridFSDownloadStream );

puis

file.setInputStream(gridFsResource.getInputStream());

Vous pouvez définir gridFSBucket dans MongoConfiguration comme ceci

@Bean public GridFSBucket getGridFSBuckets() {
MongoDatabase db = mongoDbFactory().getDb();
return GridFSBuckets.create(db);
}