MongoDB 2.4.1 C++ driver編譯和使用

來源:互聯網
上載者:User

這個版本仍然沒有解決不能編譯動態庫的問題,MongoDB這幫人發什麼神經?

原來兩個繞過的方法也不行了。

只有使用靜態庫了。

下載最新版的代碼,編譯

scons --prefix=/usr install

舊版的C++代碼會編譯報錯,因為ScopedDbConnection的建構函式變成了私人,必須通過靜態方法來建立。

 

所以調用代碼要做相應調整。

我的CMake工程配置如下:

target_link_libraries(service ${Boost_LIBRARIES} booster loki cryptopp mongoclient)

應該沒有問題了。

 

分享一下我的C++封裝類:

#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 MongoSession {
 public:
    /**
    * 從串連池中擷取串連,如果沒有則建立一個
    */
    MongoSession(string const& host, double socketTimeout=0);

    /**
    * 歸還串連到池中
    */
    ~MongoSession();
   
    /**
    * 返回已經獲得的串連
    */
    mongo::DBClientBase& GetDBClientBase();

 private:
    std::auto_ptr<mongo::ScopedDbConnection> con_;
};


#endif

MongoDB 的詳細介紹:請點這裡
MongoDB 的:請點這裡

推薦閱讀:

CentOS編譯安裝MongoDB

CentOS 編譯安裝 MongoDB與mongoDB的php擴充

CentOS 6 使用 yum 安裝MongoDB及伺服器端配置

Ubuntu 13.04下安裝MongoDB2.4.3

如何在MongoDB中建立新資料庫和集合

MongoDB入門必讀(概念與實戰並重)

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.