mongo - cxx driver

安装

1
2
# brew
brew insall mongo-cxx-deriver

其他参考这里

示例

官方示例参考这里

连接数据库

1
2
3
mongocxx::instance instance{};
mongocxx::uri uri("mongodb://192.168.4.13:27017");
mongocxx::client client(uri);

读取数组

1
2
3
4
5
6
7
8
auto arr_element = doc["contribs"];
if (arr_element && arr_element.type() == bsoncxx::type::k_array) {
bsoncxx::array::view arr(arr_element.get_array().value);
std::cout << arr.length() << std::endl; // 67; not count of elements
for (auto e: arr) {
std::cout << "E " << e.get_utf8().value.to_string() << std::endl;
}
}