1

Here i want to save one object to MongoDB using Java. I found Morphia, Jongo, Springs are providing framework to achieve it.

To store the images to mongoDB i found GridFS

Here my problem is,

1. I have one object it contains both data as well as image. I have to store and have to do lot of mathematical calculation towards the fields in it. As well i want to search a particular image if certain condition satisfies..??

2. If i separate the image with object store image using GridFs and data as BSon data, then how can link this document with image..??

3. While i'm separating the data from object, if that data itself exists 16 MB means how i have to handle this ..?? For this also if i go for GridFs means it is converting into Chunks I want to analyse field by field ..??

4. At particular time can i find the size of the Object in java before write it into mongodb..??

Can any one please suggest me to over come this problem..any link..or any idea which java framework with MongoDB will be very efficient to handle all this real time scenario..??

More informations about the data structure:

I want to store complex business object. For example if i want to store one classroom object it contains many students each student contains many photos. In classroom object has its own data.And each student has its own data with list of photos. I have to efficiently query and analyse the data here. It may be classroom wise or student wise.

Philipp
  • 67,764
  • 9
  • 118
  • 153
Suseendran P
  • 557
  • 1
  • 5
  • 18

1 Answers1

0

You can save the metadata for the image in a normal document which also includes the GridFS filename under which the binary data can be found.

Putting the metadata on GridFS would mean that it would become a binary lumb of data. You then have no longer any way to query it execpt by its filename. So when your image metadata also risks exceeding the 16MB limit, it means that you should reconsider your database schema and separate it into multiple documents.

When you want to do data analysis on both classroom and student level, you should put each student in an own document and then either have the classrooms reference the students or the students reference the classrooms (or both).

I assume that your students will add more and more images during the lifetime of the application. MongoDB does not like documents which grow over time, because growing objects mean that MongoDB needs to constantly reallocate their storage space which is a performance killer on write operations. When that's the case you should also have a separate document per image which references the student they belong to. But when this is not the case (list of images is created once at creation and then rarely changed) you should rather embed the images as an array in the student-object.

Regardless of if you embed or reference the images, the image documents/objects should only contain the meta-data while the binary image data itself should be stored on GridFS and referenced by its filename from the image document.

Philipp
  • 67,764
  • 9
  • 118
  • 153
  • @Philipp- here i want to store complex business object.For example if i want to store one classroom object it contains many students each student contains many photos.In classroom object has its own data.And each student has its own data with list of photos. I have to efficiently query and analyse the data here. It may be classroom wise or student wise. - Thanks – Suseendran P Nov 14 '13 at 04:57
  • @SuseendranP Updated your question and my answer. – Philipp Nov 14 '13 at 08:51
  • @Philipp- Thanks for your edition. I having one classroom object i'm saving it as BSON it contains student reference. same way i'm storing student as BSON, student photo ll rarely grow so embedded the image as array. But any of the time any of student data exists 16 MB how can i handle this scenario ..?? why i speaking more about BSON means i want to manipulate data frequently..like search, adding ect..Thanks – Suseendran P Nov 14 '13 at 09:24
  • @SuseendranP What data are you storing in the student documents which could grow beyond 16MB per student except for the binary image data, which you should store on GridFS? – Philipp Nov 14 '13 at 09:48
  • @Philipp- Thanks for your response. You suggest like "embed the images as an array in the student-object", while i'm embedding the image in same document i'm not sure about all student ll get below 16 MB image size. i have to check each student object for switching between embed and GridFS..??Ple excuse me if i was misunderstood. - Thanks. – Suseendran P Nov 14 '13 at 10:58