Sunday, January 26, 2014

MongoDB Noncopyable error

I was fiddling today with a C++ spaghetti and ran into this error:
/usr/include/boost/noncopyable.hpp|27|error: ‘boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&)’ is private
What it comes down to is that the mongo::DBClientConnection cannot be copied, we have to pass it by reference, like this:
void create_connection()
{
    mongo::DBClientConnection c;
    c.connect("localhost");
    do_something(c);
}

void do_something(mongo::DBClientConnection & c)
{
    // do something with the connection
}