C++连接mongodb

Qt使用MongoDB的c++接口:连接、创建、写入、读取 使用c++接口,连接数据库,创建表格,查找表格中的数据,写入一个图片文件,并从数据库中拿取图片数据再保存为图片。。例如:好了,直接上代码。 阅读详情

本文的安装过程以archlinux为例

首先安装boost

sudo pacman -S boost

下载C++ diver

http://dl.mongodb.org/dl/cxx-driver

解压之后,将src中的mongo拷入 /usr/src下

用官网的例子,创建一个test.cpp

#include <cstdlib>
#include <iostream>
#include "mongo/client/dbclient.h"

void run() {
  mongo::DBClientConnection c;
  c.connect("localhost");
}

int main() {
  try {
    run();
    std::cout << "connected ok" << std::endl;
  } catch( const mongo::DBException &e ) {
    std::cout << "caught " << e.what() << std::endl;
  }
  return EXIT_SUCCESS;
}

编译一下

g++ test.cpp -pthread -lmongoclient -lboost_system -o test

运行

./test

输出 connected ok 成功

C++连接MongoDB的接口实现 阅读详情

相关推荐

在Windows上用cpp连接CentOS上的Mongodb(一)

系列文章目录 在CentOS上安装Mongodb 在Windows上编译Mongodb的cpp驱动 vs的相关配置 cpp连接Mongodb的简单操作 文章目录系列文章目录前言一、环境二、下载Mongodb三、解压四、配置五、测试六、配置环境变量七、总结八、参考文献 前言 因为学业需要,我打算在CentOS上搭建Mongodb,并在Windows上用cpp程序连接。对CentOS的操作也基本是在Windows上完成的。 一、环境 CentOS 8.2 Mongodb 4.4.1 二、下载Mo

acmwwh的博客 276

C++调用MongoDB数据库

C++调用MongoDB数据库(一) 一、简介 本篇文章主要讲述如何使用C++调用MongoDB数据库实现增、删、查、改。 MongoDB MongoDB是一个基于分布式文件存储的数据库,由C++语言编写,一般多用于WEB应用进行可扩展的高性能数据存储。MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。它支持的数据结构非常松散,是类似json的bson格式,因此可以存储比较复杂的数据类型。 MongoDB文档 MongoDB中的记录是一个文档,它是由

m0_46185044的博客 7171

在Windows上用cpp连接CentOS上的Mongodb(三)

系列文章目录 1. 在CentOS上安装Mongodb 2. 在Windows上编译Mongodb的cpp驱动 3. vs的相关配置 4. cpp连接Mongodb的简单操作 文章目录系列文章目录一、添加头文件二、添加库文件三、添加动态文件四、添加其他配置1.预处理器2.语言环境设置为C++17五、测试代码六、参考文献 一、添加头文件 C:\boost_1_74_0 F:\Mongodb\include\bsoncxx\v_noabi\bsoncxx F:\Mongodb\include\mongo

acmwwh的博客 372

mongodb学习笔记--C++操作mongodb

mongodb学习笔记–C++操作mongodb   学习mongodb过程当中,必须学习的就是用C++(Java、PHP、C#等)操作mongodb,这里讲述C++操作mongodb,在官方提供的mongo-cxx-driver驱动中有相关的操作例子,可以结合例子学习,目录是mongo-cxx-driver-legacy-1.0.0-rc0\src\mongo\client\examples,这里针对几个重要的点。

wonderomg 1万+

c++连接mongodb出错

上一篇好不容易编译出了mongoclient.lib http://blog.csdn.net/kuaile123/article/details/9963925 当c++连接mongodb时还是出了错。 按照网上写的简单的程序,出了错误,先记录一下,要不然哪天弄的时候又不记得了,也没查到有人有类似的错误。 添加了boost路径和boost/stage/lib 添加了js的路径 添加

KUAILE123的专栏 2028

mongodb的c++连接接口

里面包含了c+调用mongodb接口的所用到的lib,dll,include库等以及对应的boost文件,可以在vs2015上使用,亲测过

C++ 实战Mongodb CRUD操作基本用法

mongo c++ driver crud + 高级操作

weixin_44834554的博客 2847

ESD笔记(三)_常用ESD保护电路优缺点

根据ESD防护器件的TLP I-V特性我们可将ESD器件分为回滞类和非回滞类两种; 回滞类的ESD器件包括NPN三极管、栅极接地 NMOS ( GGNMOS, Gate-grounded NMOS )、可控桂(SCR, siliconcontrolled rectifier)等。 非回滞类的ESD器件包括二极管、二极管串、沟道工作的MOS管、PNP三极管、栅极接电源的PMOS(GDPMOS)等,与回滞类ESD器件相比,其TLP曲线没有负阻区的存在。 常用于ESD防护的器件包括PN结二极管、GGN

weixin_47139649的博客 1万+

在Windows上用cpp连接CentOS上的Mongodb(二)

系列文章目录 在CentOS上安装Mongodb 在Windows上编译Mongodb的cpp驱动 vs的相关配置 cpp连接Mongodb的简单操作 文章目录系列文章目录前言一、下载Mongodb的c驱动和cpp驱动二、编译c驱动1.把下载的包解压到相应目录2.创建编译输出文件C:\mongo-c-driver3.Cmake1) win+R打开命令行2)cd 到解压目录3)执行cmake命令4.使用VS编译1)用VS打开项目文件2)选择Debug、x64模式3)选中工程:ALL_BUILD并编译4)

acmwwh的博客 205

Ansys 2022R2安装教程

Ansys 2022r2 手把手安装过程

Sim Pro的博客 3万+

Intel Arc显卡玩《三角洲行动》报错?手把手教你修改注册表跳过验证

本文针对Intel Arc显卡用户在运行《三角洲行动》时遇到的驱动验证报错问题,提供了详细的解决方案。通过安全修改Windows注册表,添加特定键值以跳过游戏驱动兼容性验证,并结合游戏内图形设置与Intel驱动面板的优化建议,旨在帮助玩家顺利进入游戏并提升游戏帧率与运行稳定性。

weixin_29310605的博客 707

编译MongoDB,C++连接MongoDB测试

from : http://www.linuxidc.com/Linux/2011-11/46957.htm C++ Language Center 点击打开链接 C++ driver download 点击打开链接 Scons安装步骤:  cd build/scons  python setup.py install   编译驱动之前需要安装p

mniwc的专栏 1227

欧姆龙PLC EIP通讯配置方法

欧姆龙EIP通讯配置方法

weixin_59671695的博客 6162

C++连接MongoDB的增删查改

1、前置条件需要安装好MongoDB的驱动(mongocxx),mongo跑起来。 2、项目包含相关头文件和库,例如: INCLUDEPATH += "/usr/local/include/mongocxx/v_noabi" INCLUDEPATH += "/usr/local/include/bsoncxx/v_noabi" LIBS += -L/usr/local/lib/ -lbson...

weixin_33656634的博客 2671

LSF实践专题(15):LSF队列优先级以及抢占功能初探

在LSF暂停作业时,会向作业发送一个SIGTSTP信号,并且将作业状态变成SSUSP(system suspend),表示被系统暂停,这时,最好是作业的应用能够捕获和处理SIGTSTP信号,否则,即使在LSF中,作业会被认为暂停了,并且释放了slots资源,但是在实际OS中,作业进程仍然在继续,并且不会释放CPU等计算资源。是指LSF自动将低优先级作业暂停(suspend),将空余出来的资源交给高优先级队列中的作业使用,等到高优先级队列的作业结束后,再将被暂停的作业恢复(resume)并继续运行。

richycn的博客 1931

泛微ecology9二次开发-附件上传接口实战:从表单创建到数据库存储解析

本文详细解析了泛微ecology9二次开发中的附件上传接口实战,从测试环境搭建、数据库表结构解析到接口代码实现,提供了全面的开发指南。重点介绍了文件上传的核心逻辑、常见问题排查及高级应用场景,帮助开发者高效实现附件上传功能并优化系统性能。

weixin_30836759的博客 484

c++ 连接 MongoDB replica-set

MongoDB的官方文档描述了如何使用连接字符串的正确格式来支持single server和replica-set server,并且声称官方驱动都支持。http://docs.mongodb.org/manual/reference/connection-string/但实际上c++驱动仍然沿用旧的方式,而且文档描述相当少。可以通过这个讨论让大家看到MongoDB c++驱动有多讨厌。http:

Dean Chen的专栏 6471

基于Simulink进行微电网中DC-DC变换器的仿真建模

微电网:包括可再生能源发电设备、储能系统和负载,可以独立于大电网运行,也可以并网运行。重要性提高能源可靠性:通过本地化供电减少对外部电网的依赖。促进可再生能源利用:支持高效整合多种可再生能源。挑战多源管理:不同类型的能源产生方式各异,需设计灵活的电源管理系统。能量转换效率:需要高效的能量转换装置来确保能源的有效利用。首先明确要模拟的任务内容。设计一个能够在不同输入条件下为微电网提供稳定输出电压的DC-DC变换器。根据微电网的工作状态调整控制策略以维持最佳性能。

amy_mhd的博客 161

mongodb连接池c++封转

from : http://www.oschina.net/code/snippet_116907_16529 001 //函数返回0:成功 >0 出错 002 class cmongo{   003     public: 004         //默认构造函数,默

mniwc的专栏 3131

Autosar代码包初识 2 - 如何编译Vector包内Demo工程

Vetcor autosar代码包Demo工程编译,GreenHills,RH850,Autosar,Davinci COnfigurator

weixin_42412049的博客 5193

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

MongoDB Primary---->编译MongoDB,C++连接MongoDB测试

编译MongoDB,C++连接MongoDB测试" style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; color:rgb(51,51,51); te

秋水之城 740

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

使用C++连接MongoDB集群

项目中用到了MongoDB,由于担心将来接口请求量过大后,单服务会出现宕机。所以研究了下mongo的集群,但发现了好多问题,在这里记录下。 我的编译环境:Centos 6.8、mongodb3.0+、mongodbC++ driver 2.6。

Lojze 3161

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Windows系统C++连接到Mongodb的配置

Windows系统C++连接到Mongodb的配置准备工作编译mongo-c-driver关于mongo-cxx-driver-r3.2.1的配置 准备工作 下载并安装Mongodb ; 下载并安装CMake用于编译 (https://cmake.org/download/); ; 下载mongo-c-driver源码并解压 (https://github.com/mongodb/mongo-c-driver/releases); 下载 mongodb c++ driver 并解压 (https://gi

Z__XY_的博客 1502

MongoDB Primary(编译MongoDB,C++连接MongoDB测试, GLIB INSTALL)

C++ Language Center 点击打开链接 C++ driver download 点击打开链接 Scons安装步骤: cd build/scons python setup.py install 编译驱动之前需要安装pcre 和 sc...

chenqunan3231的博客 88

编写简单的连接MongoDB数据库C++程序 && 解决编译C++程序时链接MongoDB动态库失败的问题

一. 安装好mongo数据库以后,创建一个用来链接数据库的简单C++程序mon2.cpp,发现很多网站都用这个程序做示例。 不过重点在于如何让这个程序真正可以跑起来显示出来结果,着实费了一番功夫。 1 #include 2 #include "client/dbclient.h" 3 4 using namespace mongo; 5 using namespace

long12310225的专栏 445
上一篇: 使用php-screw对php站点进行加密
下一篇: 解决c/c++编译时 note: this is the location of the previous definition
Andos
博客等级 码龄16年 9粉丝 30原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址