I want to use the mongo-cxx-driver to upload files but can't find a way. Tried to use the gridfs feature of mongodb but couldn't integrate. Using current stable version mongodb-cxx-driver (3.1.1).
gridFs throws error when try to store file like this:
gfs.storeFile("filepath", "filename");
Error: store_file: /usr/include/boost/smart_ptr/scoped_ptr.hpp:99: T* boost::scoped_ptr::operator->() const [with T = mongo::AtomicWord]: Assertion `px != 0' failed. Aborted (core dumped)
Also if mongo client is initialized it provides segmentation fault error.
#include "mongo/client/dbclient.h"
#include <iostream>
#include <cstdlib>
using namespace std;
using namespace mongo;
int main(int argc, const char** argv) {
cout<<"good so far"<<endl;
client::GlobalInstance instance; //everytime producing segmentation fault
if (!instance.initialized()) {
std::cout << "failed to initialize the client driver: " << instance.status() << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "Successfully initialized the client driver: " << instance.status() << std::endl;
}
return EXIT_SUCCESS;
}
That looks like the legacy client, not the stable 3.1.1 version.
GridFS is not yet available for the stable client (initial priority was on essential CRUD features), but GridFS is under active development and will be available in the 3.2.0 release expected in the next couple months. If you want to keep an eye on progress, the relevant JIRA ticket is CXX-1130.