23 #include <core/exception.h>
25 #include <bsoncxx/exception/exception.hpp>
26 #include <bsoncxx/types.hpp>
28 using namespace bsoncxx;
32 get_dotted_field(
const document::view &doc,
const string &key)
34 bsoncxx::document::view subdoc{doc};
35 std::string subkey = key;
37 while ((pos = subkey.find(
".")) != std::string::npos) {
38 subdoc = subdoc[subkey.substr(0, pos)].get_document().view();
39 subkey = subkey.substr(pos + 1);
41 return subdoc[subkey];
49 std::pair<std::string, std::string>
50 split_db_collection_string(
const std::string &dbcollection)
52 size_t point_pos = dbcollection.find(
".");
53 if (point_pos == dbcollection.npos) {
55 "Improper database collection string: '%s', expected string of format '<dbname>.<collname>'");
57 return make_pair(dbcollection.substr(0, point_pos),
58 dbcollection.substr(point_pos + 1, std::string::npos));
66 check_mongodb_ok(
const bsoncxx::document::view &reply)
72 return reply[
"ok"].get_double() > 0.5;
73 }
catch (bsoncxx::exception &e) {