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
运行结果:
相关文章推荐
- 分享微信开发Html5轻游戏中的几个坑
- 如何在 Fedora 上安装 MongoDB 服务器
- PHP添加yaf xhprof mongodb 同理
- mongodb安装
- 如何在 Ubuntu 上安装 MongoDB
- 信息安全聚合 Sec-News 的重构之路
- perl操作MongoDB报错undefined symbol: HeUTF8解决方法
- C#中使用1.7版本驱动操作MongoDB简单例子
- 使用zabbix监控mongodb的方法
- Node.js的MongoDB驱动Mongoose基本使用教程
- MongoDB系列教程(四):设置用户访问权限
- node.js连接mongoDB数据库 快速搭建自己的web服务
- php实现的mongodb操作类实例
- 解决mongodb在ubuntu下启动失败,提示couldn‘t remove fs lock errno:9 Bad file descriptor的错误
- 在PostgreSQL的基础上创建一个MongoDB的副本的教程
- 关于mongoose连接mongodb重复访问报错的解决办法
- java操作mongodb示例分享
- php对mongodb的扩展(初出茅庐)
- 作为PHP程序员应该了解MongoDB的五件事
- 基于MySQL到MongoDB简易对照表的详解