Compiling and using MongoDB 2.4.1 C ++ driver

Source: Internet
Author: User
Tags install mongodb

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 and compile the latest code.

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_pai_session_h _
# Define business_util_pai_session_h _

# Include <string>
# Include <memory>
# Include <mongo/client/connpool. h>

Using std: string;


Class reset session {
Public:
/**
* Obtain the connection from the connection pool. If no connection exists, create
*/
Reset SESSION (string const & host, double socketTimeout = 0 );

/**
* Return the connection to the pool
*/
~ Reset SESSION ();

/**
* Returns the obtained connection.
*/
Mongo: DBClientBase & GetDBClientBase ();

Private:
Std: auto_ptr <mongo: ScopedDbConnection> con _;
};


# Endif

MongoDB details: click here
MongoDB: click here

Recommended reading:

CentOS compilation and installation of MongoDB

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

How to create a new database and set in MongoDB

MongoDB beginners must read (both concepts and practices)

  • 1
  • 2
  • Next Page

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.