Search code examples
c++mongodbmongo-cxx-driver

Is there a way for downloading arbitrary ranges from a GridFS collection's file using the mongocxx driver?


I need random access to my files stored in a MongoDB using the GridFS specification. It seems that the C++ driver (mongocxx) doesn't provide an interface for doing that. I can create a mongocxx::gridfs::downloader object from a mongocxx::gridfs::bucket, however the only "lower level" read operation I can find is

std::size_t read(std::uint8_t *buffer, std::size_t length)

What I miss is a third parameter std::size_t offset. My current workaround is to circumvent the mongocxx::gridfs API completely, i.e., querying the chunks collection and creating the needed buffer manually. But I actually would like to use the driver's API for that.

Is there an API for my use case in the mongocxx driver that I didn't see or should I write a feature request?


Solution

  • After having a closer look into all related sources and after discussing this question also in the mongodb user group, the answer to this question is

    No, by now there is no API for partial file retrieval using the GridFS API of the mongo C++ driver.

    I have filed an a feature request in the MongoDB JIRA system for it.