Search code examples
c++mongodbgridfsmongo-cxx-driver

Mongodb C++ Driver and GridFS support


I want to access GridFS from my C++ application. I found that there are two C++ APIs for MongoDB: a modern mongocxx-3 and a legacy mongocxx-1.

Mongocxx-1 contains some classes to work with GridFS (like GridFile), but the modern API does not.

Is there any way to use gridfs from the modern api?


Solution

  • The C++11 driver currently does not have a dedicated API for GridFS, although we're adding one for the release (3.2.0). In the meantime, it's possible to manually query the files and chunks collections for your GridFS buckets through the collection API, although using it for inserting new files and chunks documents is rather complex and likely not worth the effort. Since all supported drivers store GridFS files the same way in the database, you can always insert documents with a different driver and query them manually with the C++ driver. (Once 3.2.0 gets released, you'll also be able to read the GridFS files stored with a different driver with the C++ driver API).