Mongodb的c++开发环境部署vs2015

需要条件:

Mongodb3.4

Libbson1.9.2

Mongo-c-driver-1.9.2

Mongo-cxx-drive-releases-v3.2

Vs2015

Boost1.68

mongodb-win32-x86_64-2008plus-ssl-3.4.23-signed.msi

打包下载地址:https://download.csdn.net/download/qq_34792744/12076294

Mongodb的c++开发环境部署vs2015

前提,我本机已经装好了vs2015和boost(环境变量中已设置了相应的路径)

  1. libbson安装

地址:https://github.com/mongodb/libbson/tree/1.9.2

Cmake生成,选择vs2015 x64

更改cmake_install_prefix路径

点击Generate->完成点击Open Project

ALL_BUILD的Debug/Release模式下生成;之后INSTALL的Debug/Release模式下生成。

 

完成后生成如下文件:

  1. mongo-c-driver-1.9.2安装

下载路径:https://github.com/mongodb/mongo-c-driver/tree/1.9.2

Cmake安装,选择vs2015 x64,确认弹出错误框

 

修改其中的一些路径信息,这里用到了第一步生成的一些文件。

 

点击Generate->完成Open Project

在生成/批生成,分别选择ALL_BUILD的Debug和Release和INSTALL的Debug和Release生成。

完成后生成如下文件。

 

3.mongo-cxx安装

下载路径:https://github.com/mongodb/mongo-cxx-driver/tree/releases/v3.2

Cmake安装,修改相应路径,这里用到了前2步生成的文件

Generate->完成Open Project

在生成/批生成,分别选择ALL_BUILD的Debug和Release和INSTALL的Debug和Release生成。

完成后生成如下文件。

到这里就算结束了,来代码测试一下

打开vs/visual c++/常规/空项目

右击项目属性,在VC++目录中更改包含目录和库目录。

在c/c++中添加boost到附加包含目录

 

在连接器/输入中写入lib

把mongocxx3.2-/bin下面的mongocxx.dll\bsoncxx.dll

把libbson1.9.2-/bin下面的libbson-1.0.dll

把libmongoc1.9.2-/bin下面libmongoc-1.0.dll

这几个文件放到项目里,这里就可以了,测试代码

#include <chrono>

#include <bsoncxx/builder/basic/array.hpp>

#include <bsoncxx/builder/basic/document.hpp>

#include <bsoncxx/builder/basic/kvp.hpp>

#include <bsoncxx/types.hpp>

#include <mongocxx/client.hpp>

#include <mongocxx/instance.hpp>

#include <mongocxx/uri.hpp>

using bsoncxx::builder::basic::kvp;

using bsoncxx::builder::basic::make_array;

using bsoncxx::builder::basic::make_document;

int main(int, char**) {

// The mongocxx::instance constructor and destructor initialize and shut down the driver,

    // respectively. Therefore, a mongocxx::instance must be created before using the driver and

    // must remain alive for as long as the driver is in use.

    mongocxx::instance inst{};

    mongocxx::client conn{ mongocxx::uri{} };

    auto db = conn["test"];

    // TODO: fix dates

    // @begin: cpp-insert-a-document

    bsoncxx::document::value restaurant_doc = make_document(

         kvp("address",

             make_document(kvp("street", "2 Avenue"),

                  kvp("zipcode", 10075),

                  kvp("building", "1480"),

                  kvp("coord", make_array(-73.9557413, 40.7720266)))),

         kvp("borough", "Manhattan"),

         kvp("cuisine", "Italian"),

         kvp("grades",

             make_array(

                  make_document(kvp("date", bsoncxx::types::b_date{ std::chrono::milliseconds{ 12323 } }),

                      kvp("grade", "A"),

                      kvp("score", 11)),

                  make_document(

                      kvp("date", bsoncxx::types::b_date{ std::chrono::milliseconds{ 121212 } }),

                      kvp("grade", "B"),

                      kvp("score", 17)))),

         kvp("name", "Vella"),

         kvp("restaurant_id", "41704620"));

    // We choose to move in our document here, which transfers ownership to insert_one()

    auto res = db["restaurants"].insert_one(std::move(restaurant_doc));

    system("pause");

    // @end: cpp-insert-a-document

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值