Compiling and using MongoDB 2.4.1 C ++ driver

Source: Internet
Author: User

This version still does not solve the problem that dynamic libraries cannot be compiled. What are the nerves of MongoDB?

It turns out that the two bypass methods will not work either.

Only static databases are used.

Download the latest versionCode, Compile

 
Scons -- prefix =/usr install

An error is reported when the old c ++ code is compiled, because the scopeddbconnection constructor is private and must be created through static methods.

Therefore, the calling code must be adjusted accordingly.

The configuration of my cmake project is as follows:

 
Target_link_libraries (Service $ {boost_libraries} booster Loki cryptopp encryption client)

There should be no problem.

Share my c ++ encapsulation class:

# Ifndef business_util_mongo_session_h _ # define business_util_mongo_session_h _ # include <string> # include <memory> # include <Mongo/client/connpool. h> Using STD: string; Class reset session {public:/*** get the connection from the connection pool. If no connection exists, create a */Reset SESSION (string const & host, double sockettimeout = 0);/*** return to connect to the pool */~ Reset SESSION ();/*** return the obtained connection */Mongo: dbclientbase & getdbclientbase (); Private: STD: auto_ptr <Mongo :: scopeddbconnection> con _ ;}; # endif

 
# Include "Business/util/mongo_session.h" using namespace Mongo; scheduled session: scheduled session (string const & host, double sockettimeout): con _ (Mongo: scopeddbconnection: getscopeddbconnection (host, sockettimeout) {} reset session ::~ Reset SESSION () {con _-> done ();} dbclientbase & reset session: getdbclientbase () {return con _-> conn ();}

The usage is simple:

Shared_ptr <shortsession> shortsession = shortsessionfactory: getsession (); bsonobjbuilder condition; condition. append ("Address", address); Mongo: Query query_condition (condition. OBJ (); bsonobj result = Invalid session-> getdbclientbase (). findone ("your_collection", query_condition); return! Result. isempty ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.