lundi 25 mai 2015

Can't call bsoncxx::document::value::view()

I'd like to look at the results of retrieving a single document from a MongoDB using the C++ 3.0 driver. The driver documentation describes the view() method of the bsoncxx::document::value class (which is returned by mongocxx::collection::find_one). When I attempt to use it like this:

#include <bsoncxx/document/view.hpp>
#include <bsoncxx/document/value.hpp>
#include <mongocxx/instance>
#include <mongocxx/client>

mongocxx::instance inst{};
mongocxx::client conn{};
bsoncxx::document::view doc;

auto db = conn['test'];

try {
    auto docObj = db['collection'].find_one(document{} <<
        "field" << "value" << finalize);
    doc = docObj.view();
} catch (mongocxx::exception::query e) {
    std::cerr << "Couldn't retrieve document";
    return NULL;
}

...

I get the following compilation error:

error: 'struct core::v1::optional<bsoncxx::v0::document::value>' has no member named 'view'

at the line

doc = docObj.view();

What am I doing wrong? If this is not the the correct idiom for using find_one(), what should I be using instead?

Aucun commentaire:

Enregistrer un commentaire