Arreme_N_A
(Arreme N/A)
February 25, 2023, 5:07pm
#1
Hello! I have a quick question just to make sure I’m not actually missing something.
I have just upgraded to version 3.8-pre (master) from 3.6. Before, I could get a string element like “element.get_utf8().value.to_string()”. Now get_utf8() is deprecated and the method get_string() gives the following error.
img_array is of type bsoncxx::v_noabi::array::view
Also there is no to_string method anymore.
From bsoncxx::document::view this conversion is implicit and seems to work.
As said, is this normal?
Hi @Arreme_N_A ,
You can refer to the example shown here for this conversion
#include <mongocxx/pool.hpp>
#include <mongocxx/uri.hpp>
namespace {
std::string get_server_version(const mongocxx::client& client) {
bsoncxx::builder::basic::document server_status{};
server_status.append(bsoncxx::builder::basic::kvp("serverStatus", 1));
bsoncxx::document::value output = client["test"].run_command(server_status.extract());
return bsoncxx::string::to_string(output.view()["version"].get_string().value);
}
void watch_until(const mongocxx::client& client,
const std::chrono::time_point<std::chrono::system_clock> end) {
mongocxx::options::change_stream options;
// Wait up to 1 second before polling again.
const std::chrono::milliseconds await_time{1000};
options.max_await_time(await_time);
auto collection = client["db"]["coll"];
2 Likes