I want to upload files and retrieve them from mongodb in spring boot application. But I don't want to use GridFSTemplate because my file size will not be greater than 16 MB. I am not choosing GridFSTemplate because none of the requirements mentioned in link https://docs.mongodb.com/manual/core/gridfs/#faq-developers-when-to-use-gridfs do not meet my requirements.
Is working with Document to save files and retrieve them using MongoTemplate a good approach?
MyDocument definition will look like
@Document
public class MyDocument {
@Id
private String id;
private String emailId;
private String docType;
@CreatedDate
private DateTime created;
@LastModifiedDate
private DateTime modified;
private File document;
}
Storing file
MyDocument document = new MyDocument();
document.setEmailId("abc@gmail.com");
document.setDocType("passport");
document.setDocument(file);
mongoTemplate.insert(document);
I want to store file along with some information like email. Later I will retrieve this file based on email parameter.
Please suggest if this approach is good or any other better solution is appreciated.