惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
美团技术团队
量子位
M
MIT News - Artificial intelligence
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
小众软件
小众软件
博客园 - 司徒正美
罗磊的独立博客
云风的 BLOG
云风的 BLOG
B
Blog RSS Feed
博客园 - 聂微东

博客园 - think8848

[原]使用BPI-R4开发板实现5G上网、Wi-Fi AP、文件共享和Docker服务 [原]挂载oVirt虚拟机磁盘 Mapnik 3.0.20编译安装 [原]Webpack 3 + AngularJS1.* + Bootstrap 4 + Mapbox-gl VSCode下调试mocha测试用例 Mapbox Studio Classic 闪退问题解决方案 EventEmitter事件处理器中的this问题 Rappid 消除试用版的弹出框 CentOS7.2 1511部署RabbitMQ shp2pgsql向postgresql导入shape数据 node.js的Promise库-bluebird示例 [原]Docker部署SuperMap8.1.1 Docker初步 node.js 调试问题 [原]OpenStreetMap数据瓦片服务性能篇 [原]CentOS7.2部署KVM虚拟机 [原]使用node-mapnik和openstreetmap数据初步搭建瓦片服务 [原]使用node-mapnik生成openstreetmap-carto风格的瓦片 [原]CentOS7.2部署node-mapnik
mongocxx-driver编译安装
think8848 · 2018-06-23 · via 博客园 - think8848

1. 确保安装epel

yum install -y epel-release

2. 按照《CentOS7.2部署node-mapnik》一文中的步骤,手动安装 gcc-6.2.0 和 boost-1.65.1 

3. 按照官方文档安装MongoDB,请注意开启防火墙端口和设置SELinux相关选项,(本示例中创建了数据库 gis , dbOwner 用户名为 root ,密码为 111111 )

4.  安装编译工具及依赖项

yum install -y automake autoconf libtool cmake3 openssl-devel unzip

5. 下载解压 mongo-c-driver 源代码

wget https://github.com/mongodb/mongo-c-driver/releases/download/1.10.0/mongo-c-driver-1.10.0.tar.gz

tar -xzvf mongo-c-driver-1.10.0.tar.gz

cd mongo-c-driver-1.10.0

mkdir cmake-build && cd cmake-build

6. 编译安装

#注意后面是两个..(点号)
cmake3 -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..

make -j4

make install

ldconfig

7. 下载并解压 mongo-cxx-driver 

wget https://github.com/mongodb/mongo-cxx-driver/archive/r3.2.0.zip

unzip r3.2.0.zip

cd mongo-cxx-driver-r3.2.0

8. 编译安装

cd build

cmake3 -DCMAKE_BUILD_TYPE=Release -DBSONCXX_POLY_USE_BOOST=1 -DCMAKE_INSTALL_PREFIX=/usr/local ..

make -j8

make install

9. 添加 PKG_CONFIG_PATH 环境变量,使用 vim /etc/profile 打开文件,在最下面输入 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ,然后 source /etc/profile 应用环境变量

10. 测试libmongocxx库

10.1 登录mongodb mongo -u <user> -p <password> --authenticationDatabase <dbname> 

10.2 插入测试数据 db.points.insert({"hello": "world!"}) 

10.3 输入c++测试代码

#include <iostream>

#include <bsoncxx/json.hpp>

#include <mongocxx/instance.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/cursor.hpp>

int main(int, char**)
{
  mongocxx::instance instance{};
  mongocxx::client client{ mongocxx::uri {"mongodb://root:111111@192.168.1.67:27017/?authSource=gis"}};

  auto collection = client["gis"]["points"];

  auto cursor = collection.find({});

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

10.4 编译c++代码,生成测试程序

g++ -std=c++11 test.cpp -o test $(pkg-config --cflags --libs libmongocxx)

10.5 运行测试程序 ./test 

运行结果如下:

----------------------2019.02.21----------------------

经验证:

MongoDB 4.0.6

mongo-c-driver-1.13.1

mongo-cxx-driver-r3.4.0

也可以使用此方法编译安装