I am creating pinboard (something like http://www.pinterest.com). I am using MongoDB as database (to store all pins).
Pins {
userid,
img,
title,
description,
comments {
[userid, username, comment]
}
}
I want to store images in gridFs. How I should link gridFs file to Pins.img. There should be only one image, but could be linked in multiple pins.
I can’t figure it out.
first, you need GridFS only if the stored data, a single image, would exeed the max document size of mongodb, which is 16MB since version 1.8.
but in any case, you link two documents using a mongoref if they are in different collections. or just simply store the ID of the document holding the image data in your Pins document.
to retreive the image data, you need to query the Pins documents you want to display loop over the result and query every single image from the image documents.
this applies if you store the image in gridfs or in simple binary fields inside a normal document (the php documentation is outdated and still refers to 4MB max document size, it is 16MB now).
if you resize the uploaded images to a reasonable resolution and store them as jpeg data, you would barely need 16MB anyway.