New C++ Mongo driver: how to see type and how to get string value

Viewed 6274

I've got two questions that I cannot find an answer for in the tutorial.

I get a document and then an element from the doc like this:

        bsoncxx::document::element e = doc["id"];

        if (!e || e.type() != bsoncxx::type::k_int32) return ERROR;
        int id = e.get_int32();

Is there a way to get a string value for the type, for debugging purposes? Like:

        std::cout << e.type() << std::endl;

(which doesn't work)

The second question is how to convert the utf8 type value into a std::string. This doesn't work:

        e = doc["name"];
        if (!e || e.type() != bsoncxx::type::k_utf8) return ERROR;
        string name = e.get_utf8().value;

Any tips?

2 Answers
Related