0

Just Started building an application on mongodb for file saving and retrieving and found that it has a standard specification for this purpose named as GridFS . But unfortunately i am unable to find any start up example for this in C/C++. If anyone know any thing related with it then please gives my the direction.

Edit:

I read that for storing file greater than the size of 16MB, GridFS is used, so what about the file size smaller than 16MB?..I can not get any information about it. For the smaller size, do i need to use some other process or the same GridFs?

Thanks

Saad Saadi
  • 1,031
  • 10
  • 26

1 Answers1

0

GridFS can be accessed through the class mongo::GridFS. The API is pretty self-explaining.

Alternatively, you can embed the binary data of your files in normal documents as the BSON BinData type. mongo::BSONObjBuilder has the method appendBinData to add a field with binary content to a document.

The reason GridFS exists is that there is an upper limit of 16MB per document. When you want to store data larger than 16MB, you need to split it into multiple documents. GridFS is an abstraction to handle this automatically, but it can also be used for smaller files.

In general, you shouldn't mix both techniques for the same content, as it just makes things more complicated with little benefit. When you can guarantee that your data doesn't get close to 16MB, use embedding. When you occasionally have content > 16MB, you should use GridFS even for files smaller than that.

Philipp
  • 67,764
  • 9
  • 118
  • 153
  • Keep in mind that large documents must be deserialized in one go and reading 16MB will take quite a bit of time. Thus, the default chunk size for GridFS is a mere 250kB so you can stream data more efficiently. – mnemosyn Oct 21 '13 at 09:55
  • Can you guys help me in this....http://stackoverflow.com/questions/19629753/replication-on-mongodb-using-visual-studio – Saad Saadi Oct 29 '13 at 08:21