您的位置:首页 > 数据库 > Mongodb

MongoDB c++ driver(四)

2016-07-03 14:44 423 查看

MongoDB c++ driver(四)

简单的查找实现

#include <iostream>

#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>

#include <mongocxx/client.hpp>
#include <mongocxx/options/find.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>

using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::open_document;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::finalize;

int main(int argc, char** args)
{
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{"mongodb://chenzw:IP:端口"}};

auto db = conn["guanwang"];
auto cursor = db["restaurants"].find({});

for (auto&& doc : cursor)
{
std::cout << bsoncxx::to_json(doc) << std::endl;
}

return 0;
}


编译、运行

$ c++ –std=c++11 3find.cpp -o 3find $(pkg-config –cflags –libs libmongocxx)

$ ./3find

运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mongodb