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

推荐订阅源

A
About on SuperTechFans
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
aimingoo的专栏
aimingoo的专栏
B
Blog
博客园 - 聂微东
博客园_首页
D
DataBreaches.Net
F
Fortinet All Blogs
小众软件
小众软件
M
MIT News - Artificial intelligence
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
F
Full Disclosure
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
腾讯CDC
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 【当耐特】
Simon Willison's Weblog
Simon Willison's Weblog
云风的 BLOG
云风的 BLOG
A
Arctic Wolf
C
Cyber Attacks, Cyber Crime and Cyber Security
G
Google Developers Blog
B
Blog RSS Feed
Attack and Defense Labs
Attack and Defense Labs
W
WeLiveSecurity
N
News | PayPal Newsroom
Recent Announcements
Recent Announcements
AI
AI
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
V2EX - 技术
V2EX - 技术
TaoSecurity Blog
TaoSecurity Blog
S
Security Affairs
Martin Fowler
Martin Fowler
Webroot Blog
Webroot Blog
P
Palo Alto Networks Blog
S
Schneier on Security
Latest news
Latest news

博客园 - 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

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