Friday, June 14, 2019

Save binary files in MongoDB with Spring-Boot

Saving binary files in MongoDB is pretty simple with Spring-Boot. You simply need to put byte[] type in the CrudRepository entity:



1
2
3
4
5
6
7
8
9
10
11
public interface BinayFilesRepository extends MongoRepository<BinaryEntity, String> {
 
}
 
@Document(BinaryEntity = "binaries")
public class BinaryEntity {
 
    private String id;
    private byte[] data;
 
}