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 ();