Announcement Announcement Module
No announcement yet.
Mongodb GridFS integration Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mongodb GridFS integration

    I started using spring-data-mongodb and I need to retrieve files from GrisFS, I'd like to know if the way I solved my use case is correct or if I'm missing something.

    I have the user uploading files and these files go to GridFS. Later the user can select one of these files and I've a persistent entity which should contain a reference to this file that I want to be able to read later. What I want to achieve is that when I save the entity only a reference to the file is stored (since the file is already in GridFS) and when I retrieve the entity an instance of com.mongodb.gridfs.GridFSDBFile is retrieved.
    This is my sample entity:
    public class GridFSDBPdfSource implements PdfSource<GridFSDBFile> {
        private String password;
        private GridFSDBFile gridFSFile;
    and this is my document:
    	"_class" : "com.sejda.model.input.GridFSDBPdfSource",
    	"password" : "the password",
    	"gridFSFile_id" : ObjectId("4eb55b0789c35b2b3fffd516")
    Now I managed to have the expected behavior creating custom converters and what I'd like to know if this is the right way to do it or if there is any way I can annotate the gridFSFile to have spring data automagically retrieve the gridFSFile when I retrieve the entity.
    I tried annotating the field with DBRef but I ended up with a StackOverflow.