2

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;
}
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Rashik
  • 93
  • 10

1 Answers1

0

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.

xdg
  • 2,975
  • 19
  • 17
  • Thanks a lot. One thing i am failing to understand then why client driver is being initialized like legacy client in **"mongo-cxx-driver/src/mongo/client/examples"** folder. And another question could you please give me a heads up why segmentation fault occurs if i use legacy client? – Rashik Jan 10 '17 at 04:27
  • I have edited the question and provided a sample code. Thank you. – Rashik Jan 11 '17 at 04:44
  • @RashikIslam: I'm unable to reproduce your segmentation fault. When I run your code on my local machine against legacy-1.1.2, it prints "Successfully initialized the client driver: OK". Could you please open a thread at https://groups.google.com/forum/#!forum/mongodb-user for debugging this issue further? Please include information about your operating system, build toolchain, driver version, and a stack trace from gdb/lldb for the segmentation fault. Thanks! – J Rassi Jan 11 '17 at 23:40