连接数据库
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
int main(int argc, char** args)
{
mongocxx::instance inst{};
//chenzw:123 -->用户:密码 参考上一篇博客
mongocxx::client conn{mongocxx::uri{"mongodb://chenzw:123@IP:27017"}};
auto db = conn["stu"];
return 0;
}
编译代码:
c++ –std=c++11 1connect.cpp -o 1connect $(pkg-config –cflags –libs libmongocxx)
运行没报错:
./1connect