MongoDB Primary---->编译MongoDB,C++连接MongoDB测试
2011-10-15 16:24
429 查看
MongoDB
Primary---->编译MongoDB,C++连接MongoDB测试
转自:http://blog.csdn.net/crazyjixiang/article/details/6599840
C++
Language Center
点击打开链接
C++
driver download
点击打开链接
view
plainprint?
Scons安装步骤:
cd build/scons
python setup.py install
view
plainprint?
编译驱动之前需要安装pcre 和 scons
[root@:~/mongo-cxx-driver-v1.8]#scons
经过一段时间的组建,生成libmongoclient.so:
[root@:~/mongo-cxx-driver-v1.8]#ls
authTest clientTest firstExample libmongoclient.a LICENSE.txt SConstruct whereExample
client config.log httpClientTest libmongoclient.so mongo secondExample
view
plainprint?
拷贝至 /usr/local/lib下
[root@:~/mongo-cxx-driver-v1.8]#cp libmongoclient.so /usr/local/lib
view
plainprint?
安装 boost lib
./bootstrap.sh
./bjam install --prefix=/usr
。。。。。。。。。。。。。。。。。。。。华丽分界线。。。。。。。。。。。。。。。。。。。。。。。。。
view
plainprint?
另外如果你编译MongoDB的源码需要下载依赖包
ftp://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
make -f Makefile.ref
JS_DIST=/usr make -f Makefile.ref export
编译mongoDB并install
tar -xvf mongodb-src-r1.4.4.tar.gz
cd mongodb-src-r1.4.4
scons --full install
另外如果你没有boost库 ,还需要安装boost | ./bootstrap.sh -> ./bjam install --prefix=/usr/local
所有安装完后,/usr/loca include 和 libl下会有相应的mongodb的文件
。。。。。。。。。。。。。。。。。。。华丽的分界线。。。。。。。。。。。。。。
view
plainprint?
1 .C++简单连接MongoDB
#include <iostream>
#include "mongo/client/dbclient.h"
using namespace std;
using namespace mongo;
void run() {
DBClientConnection c;
c.connect("localhost"); //add port,c.connect("localhost:27017")
}
int main(void)
{
try {
run();
cout<<"connected ok"<<endl;
}catch(DBException& e){
cout<<"caught"<<e.what()<<endl;
}
return 0;
}
编译:
[root@:~/svn/mongoDB]#g++ main.cpp -lmongoclient -lboost_thread -lboost_filesystem -lboost_program_options
运行:
[root@:~/svn/mongoDB]#./a.out
connected ok
view
plainprint?
2.MongoDB自带的测试
#include <iostream>
#include "mongo/client/dbclient.h"
using namespace std;
using namespace mongo;
void run() {
DBClientConnection c;
c.connect("localhost"); //add port,c.connect("localhost:27017")
}
int main(void)
{
try {
run();
cout<<"connected ok"<<endl;
}catch(DBException& e){
cout<<"caught"<<e.what()<<endl;
}
return 0;
}
view
plainprint?
#include <iostream>
#include "mongo/client/dbclient.h"
using namespace mongo;
void printIfAge(DBClientConnection& c, int age) {
auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", QUERY( "age" << age ).sort("name") );
while( cursor->more() ) {
BSONObj p = cursor->next();
cout << p.getStringField("name") << endl;
}
}
void run() {
DBClientConnection c;
c.connect("localhost");
cout << "connected ok" << endl;
BSONObj p = BSON( "name" << "Joe" << "age" << 33 );
c.insert("tutorial.persons", p); /**< 向person表中插入数据 */
p = BSON( "name" << "Jane" << "age" << 40 );
c.insert("tutorial.persons", p);
p = BSON( "name" << "Abe" << "age" << 33 );
c.insert("tutorial.persons", p);
p = BSON( "name" << "Samantha" << "age" << 21 << "city" << "Los Angeles" << "state" << "CA" );
c.insert("tutorial.persons", p);
c.ensureIndex("tutorial.persons", fromjson("{age:1}"));
cout << "count:" << c.count("tutorial.persons") << endl; /**< 显示person表中的数据数目 */
auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", BSONObj());
while( cursor->more() ) {
cout << cursor->next().toString() << endl;
}
cout << "\nprintifage:\n";
printIfAge(c, 33);
}
int main() {
try {
run();
}
catch( DBException &e ) {
cout << "caught " << e.what() << endl;
}
return 0;
}
view
plainprint?
<pre name="code" class="cpp"><pre>
Primary---->编译MongoDB,C++连接MongoDB测试
转自:http://blog.csdn.net/crazyjixiang/article/details/6599840
C++
Language Center
点击打开链接
C++
driver download
点击打开链接
view
plainprint?
Scons安装步骤:
cd build/scons
python setup.py install
view
plainprint?
编译驱动之前需要安装pcre 和 scons
[root@:~/mongo-cxx-driver-v1.8]#scons
经过一段时间的组建,生成libmongoclient.so:
[root@:~/mongo-cxx-driver-v1.8]#ls
authTest clientTest firstExample libmongoclient.a LICENSE.txt SConstruct whereExample
client config.log httpClientTest libmongoclient.so mongo secondExample
view
plainprint?
拷贝至 /usr/local/lib下
[root@:~/mongo-cxx-driver-v1.8]#cp libmongoclient.so /usr/local/lib
view
plainprint?
安装 boost lib
./bootstrap.sh
./bjam install --prefix=/usr
。。。。。。。。。。。。。。。。。。。。华丽分界线。。。。。。。。。。。。。。。。。。。。。。。。。
view
plainprint?
另外如果你编译MongoDB的源码需要下载依赖包
ftp://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
make -f Makefile.ref
JS_DIST=/usr make -f Makefile.ref export
编译mongoDB并install
tar -xvf mongodb-src-r1.4.4.tar.gz
cd mongodb-src-r1.4.4
scons --full install
另外如果你没有boost库 ,还需要安装boost | ./bootstrap.sh -> ./bjam install --prefix=/usr/local
所有安装完后,/usr/loca include 和 libl下会有相应的mongodb的文件
。。。。。。。。。。。。。。。。。。。华丽的分界线。。。。。。。。。。。。。。
view
plainprint?
1 .C++简单连接MongoDB
#include <iostream>
#include "mongo/client/dbclient.h"
using namespace std;
using namespace mongo;
void run() {
DBClientConnection c;
c.connect("localhost"); //add port,c.connect("localhost:27017")
}
int main(void)
{
try {
run();
cout<<"connected ok"<<endl;
}catch(DBException& e){
cout<<"caught"<<e.what()<<endl;
}
return 0;
}
编译:
[root@:~/svn/mongoDB]#g++ main.cpp -lmongoclient -lboost_thread -lboost_filesystem -lboost_program_options
运行:
[root@:~/svn/mongoDB]#./a.out
connected ok
view
plainprint?
2.MongoDB自带的测试
#include <iostream>
#include "mongo/client/dbclient.h"
using namespace std;
using namespace mongo;
void run() {
DBClientConnection c;
c.connect("localhost"); //add port,c.connect("localhost:27017")
}
int main(void)
{
try {
run();
cout<<"connected ok"<<endl;
}catch(DBException& e){
cout<<"caught"<<e.what()<<endl;
}
return 0;
}
view
plainprint?
#include <iostream>
#include "mongo/client/dbclient.h"
using namespace mongo;
void printIfAge(DBClientConnection& c, int age) {
auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", QUERY( "age" << age ).sort("name") );
while( cursor->more() ) {
BSONObj p = cursor->next();
cout << p.getStringField("name") << endl;
}
}
void run() {
DBClientConnection c;
c.connect("localhost");
cout << "connected ok" << endl;
BSONObj p = BSON( "name" << "Joe" << "age" << 33 );
c.insert("tutorial.persons", p); /**< 向person表中插入数据 */
p = BSON( "name" << "Jane" << "age" << 40 );
c.insert("tutorial.persons", p);
p = BSON( "name" << "Abe" << "age" << 33 );
c.insert("tutorial.persons", p);
p = BSON( "name" << "Samantha" << "age" << 21 << "city" << "Los Angeles" << "state" << "CA" );
c.insert("tutorial.persons", p);
c.ensureIndex("tutorial.persons", fromjson("{age:1}"));
cout << "count:" << c.count("tutorial.persons") << endl; /**< 显示person表中的数据数目 */
auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", BSONObj());
while( cursor->more() ) {
cout << cursor->next().toString() << endl;
}
cout << "\nprintifage:\n";
printIfAge(c, 33);
}
int main() {
try {
run();
}
catch( DBException &e ) {
cout << "caught " << e.what() << endl;
}
return 0;
}
view
plainprint?
<pre name="code" class="cpp"><pre>
相关文章推荐
- MongoDB Primary(编译MongoDB,C++连接MongoDB测试, GLIB INSTALL)
- 神器VS2010:c/c++ &&&&&& masm->obj link编译与连接
- 编译MongoDB,C++连接MongoDB测试
- 编译MongoDB,C++连接MongoDB测试
- [原]编译MongoDB,C++连接MongoDB测试
- 编写简单的连接MongoDB数据库C++程序 && 解决编译C++程序时链接MongoDB动态库失败的问题
- C&C++编译连接过程
- <转> 模板类 声明和定义 编译 c++
- C++学习的一些笔记-->2:防止头文件多次导入造成重复编译的方法
- VC->Project settings->C/C++编译参数的设置
- MongoDB Primary---->简要介绍 和 Linux安装MongoDB 并 简单使用
- 编写简单的连接MongoDB数据库C++程序 && 解决编译C++程序时链接MongoDB动态库失败的问题
- C++ -> 在Window7 命令行下使用微软编译工具 cl.exe
- 编写简单的连接MongoDB数据库C++程序 && 解决编译C++程序时链接MongoDB动态库失败的问题
- VS2015编译连接mongodb(mongodb C++ driver)
- RT-Thread 学习笔记(十二)--- 开启基于RTGUI的LCD显示功能(2)<编译测试>
- 《C++第九周实验报告1-1》--------接第8周任务1,定义Complex类中的<<和>>运算符的重载,实现输入和输出
- <转载>在Eclipse中用JDBC连接Sql Server 2005总结
- <Effective C++>读书笔记-4
- C++编译连接过程(转)