MongoDB c++ driver(五)
2016-07-03 15:05
295 查看
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:123@IP:端口"}}; auto db = conn["guanwang"]; //finds documents whose borough field equals "Manhattan" auto cursor = db["restaurants"].find(document{} << "borough" << "Manhattan" << finalize); for (auto&& doc : cursor) //打印出"guanwang"下"restaurants"所有文档 { std::cout << bsoncxx::to_json(doc) << std::endl; } return 0; }
编译、运行
$ c++ –std=c++11 3find2.cpp -o 3find2 $(pkg-config –cflags –libs libmongocxx)
$./3find2
运行结果:
相关文章推荐
- MongoDB c++ driver(四)
- 在Linux上部署Java访问MongoDB
- MongoDB c++ driver(三)
- mongodb+php实现简单的增删改查
- MongoDB c++ driver(一)
- MongoDB用户创建
- mongodb 基本shell
- mongodb+php实现简单的增删改查
- MongoDB快速学习笔记
- MongoDB的聚合框架Aggregation Framework入门学习教程
- linux中给PHP安装mongodb的扩展
- MongoDB的聚合框架Aggregation Framework入门学习教程
- php mongodb driver : mongodb 笔记
- MongoDB数据库安装配置(Linux下/Windows下)
- mongodb java3.2驱动 测试 一些记录
- 【Mongodb】 Replica set的自动故障切换
- 【Mongodb】如何创建mongodb的replica set
- Linux下Mongodb数据库主从同步配置
- Linux下安装配置MongoDB数据库
- mongodb