title: GridFS - product images & thumbnails - what is the best DB sctructure?
body: <p>I have a e-commerce website working on MongoDB + GridFS. 
  Each product may have up to 5 images. 
  Each image has 3 thumbnails of different sizes.</p>
  
  <p>I need an advice on best DB structure for this.</p>
  
  <p>Currently I'm thinking to store image IDs and also thumb IDs (IDs from GridFS) in each product:</p>
  
  <pre><code>{
     '_id': 1, 
     'title': 'Some Product', 
     'images': [
                 {'id': '11', thumbs: {'small': '22', 'medium': '33'},
                 {'id': '44', thumbs: {'small': '55', 'medium': '66'}  
               ]
  }
  </code></pre>
  
  <p>Or would it be better to store path in GridFS?</p>
  
  <pre><code>{
    '_id': '111',
    'filename': '1.jpg',
    'path': 'product/988/image/111/'
  },
  {
    '_id': '222',
    'filename': '1.jpg',
    'path': 'product/988/image/111/thumbnail_small'
  },
  {
    '_id': '333',
    'filename': '1.jpg',
    'path': 'product/988/image/111/thumbnail_large'
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>: "path" field in GridFS is a "fake" path, not a real one. Just a quick way to find all related files. It is cheaper to have 1 indexed field than several fields with compound indexes.</p>