The read part doesn’t seem to be doing anything that I can see. It runs, but I don’t understand where I can see the results. Where can I read the data that was read from the database?
Hi Ingrid,
The example GridFS executable has three modes read, write, and list.
Using the example executable you can write (upload) a file to MongoDB GridFS as below:
> ./example_gridfs write filename_a ./photo_123.png
Where filename_a
is the filename that would be in GridFS, and photo_123.png
is the file that you would like to upload.
Once uploaded, you can check by listing the available files, for example:
./example_gridfs list
filename_a
filename_b
You can then read back (download) the file by:
./example_gridfs read filename_a > ./copy_of_photo_123.png
Where filename_a
is the file that you would like to read/download, and copy_of_photo_123.png
is the name of the target file name. Please note that the example GridFS executable dumps the content to STDOUT
. This is why the example above redirect the STDOUT
to a file.
Depending on what you’re aiming to do, you may also be interested in mongofiles. The mongofiles
utility makes it possible to manipulate files stored in your MongoDB instance in GridFS objects from the command line.
There is something I can do so the information is inserted without convertion?
GridFS is a convention on how to store files in MongoDB greater than the 16MB BSON size limitation. There are two collections that are essentially the back-end of GridFS, the fs.files and the fs.chunks collections. The fs.chunks
contains the binary representation of the files that were uploaded (unreadable). The fs.files
however, contains metadata information that would be useful to find the chunks
, for example: filename, md5, uploadDate, etc.
Is the reading part supposed to undo the conversion when trying to read?
Yes, the reading
is supposed to combine (if required) the chunks
and streamed back into the file that was uploaded.
Regards,
Wan.