1. 程式人生 > >MongoDB-C驅動的安裝

MongoDB-C驅動的安裝

MAC環境下

一、安裝openssl

$ brew install openssl
$ export LDFLAGS="-L/usr/local/opt/openssl/lib"
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"

二、下載並解壓安裝包

$ curl -LO https://github.com/mongodb/mongo-c-driver/releases/download/1.4.0/mongo-c-driver-1.4.0.tar.gz
$ tar xzf mongo-c-driver-1.4.0.tar.gz
$ cd mongo-c-driver-1.4.0
三、編譯並安裝
$ ./configure
$ make
$ sudo make install
$ brew install yelp-xsl yelp-tools
$ ./configure --enable-html-docs --enable-man-pages
$ make man html
$ brew install automake autoconf libtool pkgconfig
四、連線程式碼 test.c
  1. #include <bson.h>
  2. #include <bcon.h>
  3. #include <mongoc.h>
  4. int
  5. main (int
       argc,  
  6.       char *argv[])  
  7. {  
  8.    mongoc_client_t      *client;  
  9.    mongoc_database_t    *database;  
  10.    mongoc_collection_t  *collection;  
  11.    bson_t               *command,  
  12.                          reply,  
  13.                         *insert;  
  14.    bson_error_t          error;  
  15.    char                 *str;  
  16.    bool                  retval;  
  17.    /* 
  18.     * Required to initialize libmongoc's internals 
  19.     */
  20.    mongoc_init ();//初始化libmongoc驅動
  21.    /* 
  22.     * Create a new client instance 
  23.     */
  24.    client = mongoc_client_new ("mongodb://localhost:27017");//建立連線物件  
  25.    /* 
  26.     * Get a handle on the database "db_name" and collection "coll_name" 
  27.     */
  28.    database = mongoc_client_get_database (client, "db_name");//獲取資料庫
  29.    collection = mongoc_client_get_collection (client, "db_name""coll_name");//獲取指定資料庫和集合
  30.    /* 
  31.     * Do work. This example pings the database, prints the result as JSON and 
  32.     * performs an insert 
  33.     */
  34.    command = BCON_NEW ("ping", BCON_INT32 (1));  
  35.    retval = mongoc_client_command_simple (client, "admin", command, NULL, &reply, &error);//執行命令
  36.    if (!retval) {  
  37.       fprintf (stderr, "%s\n", error.message);  
  38.       return EXIT_FAILURE;  
  39.    }  
  40.    str = bson_as_json (&reply, NULL);  
  41.    printf ("%s\n", str);  
  42.    insert = BCON_NEW ("hello", BCON_UTF8 ("world"));//欄位為hello,值為world字串
  43.    if (!mongoc_collection_insert (collection, MONGOC_INSERT_NONE, insert, NULL, &error)) {//插入文件
  44.       fprintf (stderr, "%s\n", error.message);  
  45.    }  
  46.    bson_destroy (insert);  
  47.    bson_destroy (&reply);  
  48.    bson_destroy (command);  
  49.    bson_free (str);  
  50.    /* 
  51.     * Release our handles and clean up libmongoc 
  52.     */
  53.    mongoc_collection_destroy (collection);//釋放表物件
  54.    mongoc_database_destroy (database);//釋放資料庫物件
  55.    mongoc_client_destroy (client);//釋放連線物件
  56.    mongoc_cleanup ();//釋放libmongoc驅動
  57.    return 0;  
五、編譯執行

# gcc -o test test.c -I /usr/local/include/libmongoc-1.0 -I /usr/local/include/libbson-1.0/ -L /usr/local/lib/ -lmongoc-1.0 -lbson-1.0

# ./test 

{ "ok" : 1 }

Linux環境下

一、安裝依賴包

$apt-get install libmongoc-1.0-0
$ sudo apt-get install pkg-config libssl-dev libsasl2-dev
二、下載並解壓安裝驅動包
$ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.4.0/mongo-c-driver-1.4.0.tar.gz
$ tar xzf mongo-c-driver-1.4.0.tar.gz
$ cd mongo-c-driver-1.4.0
$ ./configure
$ make
$ sudo make install

相關推薦

MongoDB-C驅動安裝

MAC環境下 一、安裝openssl $ brew install openssl $ export LDFLAGS="-L/usr/local/opt/openssl/lib" $ export CPPFLAGS="-I/usr/local/opt/openssl/in

Python-MongoDB驅動安裝、升級

指定版本 ati class str strong 指定 pypi sharp package 安裝pip,並通過此來安裝pymongo–Python mongodb驅動 1、下載pip安裝包,下載地址:http://pypi.python.org/packages/sou

mongodb C++ Driver安裝

前言 mongocxx官網地址 http://mongocxx.org/?jmp=docs 本文的安裝版本是:mongocxx-r3.2.0.tar.gz 。 參考文件安裝過程 http://mongocxx.org/mongocxx-v3/installation/ 。根據文件過程安裝,由於系統不一

MongoDB- C# 驅動之增刪改查

MongoDB-C# 驅動之增刪改查 MongoDB.Driver是MongoDB為C#提供的一種MongoDB資料庫操作驅動,利用MongoDB.Driver 我們可以完成對MongoDB常用的增刪改查。對於MongoDB的下載及安裝部署,大家可以參見:ht

MongoDB系列二:安裝mongoDB C/C++驅動(New C++11 driver)

CentOS7.2上安裝mongodb cxx驅動筆記 1.如果CMAKE版本低於3.2版本,要先升級CMAKE 到3.2版本,安裝c++驅動要求升級到v3.2以上版本 刪除現有版本: yum remove cmake ln -s /usr/lo

MongoDB介紹、安裝及mongocxx C++驅動程式的安裝

MongoDB介紹 MongoDB 是一個基於分散式檔案儲存的資料庫。由C++語言編寫。旨在為WEB應用提供可擴充套件的高效能資料儲存解決方案。 MongoDB 是一個介於關係資料庫和非關係資料庫之間的產品,是非關係資料庫當中功能最豐富,最像關係資料庫的

MongoDBC#驅動報錯Server instance 127.0.0.1:27017 is no longer connected的解決方案

http bottom get lac soft onload nload on() kill 使用C#的MondoDB驅動,一直沒問題。結果最近,MongoCursor的ToList方法,取列表,總是報錯 Server instance 127.0.0.1:27017

MongoDB .Net Driver(C#驅動) - 內嵌數組/嵌入文檔的操作(增加、刪除、修改、查詢(Linq 分頁))

odbc article err native linq protocol remove mit 實體類 目錄 一、前言 (一) 運行環境 二、前期準備工作 (一) 創建 MongoDBContext MongoDb操作上下文類 (二)創建測試類 (三) 創建測試代碼

windows下MongodbC++驅動編譯

ODB 2.7 stat 安裝 scons 源碼 org bsp article 安裝說明:   https://github.com/mongodb/mongo-cxx-driver/wiki/Download-and-Compile-the-Legacy-Driver

MySQL,Navicat,及其C#驅動在Windows平臺的安裝

 MySQL在Windows平臺的安裝 這裡有兩個版本,一個是線上安裝包,一個是離線安裝包,這裡我們選大的,安裝過程全部點下一步就好。 安裝完成後,我們進入doc,輸入mysql –u root –p 然後輸入密碼,這時會提示“2059 - authent

C#操作Mongodb(c#mongodb驅動)

MongoDB的C#驅動基於.Net 3.5的 必要用.net 3.5以上的框架 1.對資料庫的操作主要還是增刪改查  2.瞭解c#操作mapreduce的語法 我們先佈置驅動環境,再通過例項來了解一下相關操作語法。 方法一:驅動工程直接下載: https://gi

MongoDB學習筆記(三)--MongoDBC#驅動的基本使用

官方C#驅動:https://github.com/mongodb/mongo-csharp-driver/releases 在使用C#驅動時,要在專案中新增”MongoDB.Bson.dll”和”MongoDB.Driver.dll”的引用。同時要在程式碼中

MongoDBC#驅動基本使用

MongoDB的官方C#驅動可以通過 這個連結 得到。連結提供了.msi和.zip兩種方式獲取驅動dll檔案。 通過這篇文章來介紹C#驅動的基本資料庫連線,增刪改查操作。 在使用C#驅動的時候,要在工程中新增"MongoDB.Bson.dll"和"MongoDB.Dr

mongodbc驅動使用

1. 程式安裝 預安裝 需要先安裝依賴庫OpenSSL,來建立ssl連線到MongoDB RedHat / Fedora系統: $ sudo yum install pkg-config openssl-devel cyrus-sasl-devel Debian / Ub

MongoDB 3.4版本, C# 驅動 2.4 操作

  private static string _connStr = "mongodb://127.0.0.1:27017"; private static string _dbName = "test"; const string Coll

mongodb資料庫 linux下編譯mongodbc++驅動

由於工作專案開發的需要 要使用mongodb資料庫  需要手動編譯mongo的c++庫,花費了大概兩天的時間,終於搞定,主要是上網搜資料。以下是本人收藏的幾篇部落格 https://mongodb.g

C++程式安裝解除安裝WDM驅動

編譯環境:VS2012 + WIN8 64 測試環境:VM WIN7 測試物件:WDM驅動 (sys檔案 和 inf檔案) 專案型別:Win32 Console Application 其它說明:程式碼來源於網路,經小修改而成,載入驅動方法還有很多(如SetupCopyO

MongoDB系列三:mongoDB C/C++驅動使用(New C++11 driver)

C++驅動的使用資料實在太少,應用過程中踩過不少坑,現將一些經驗整理下,共享給大家: 1、資料庫連線池: 官方提供的方法已經比較完善,簡單封裝了一下,方便使用 mongodb.h: #ifndef MongoDB_H #define MongoD

MongoDb Windows 環境下 c++ driver 安裝流程

安裝boost 1.60 位置: c:\boost_1_60_0 先編譯 libbson 進入libsson的目錄: cd mongo-c-driver-1.9.5\src\libbson mongo-c-driver-1.9.5是安裝壓縮包的解壓

安裝 MongoDB PHP 驅動 在CentOS 6.x和遇到的問題

以下安裝mongo-php-driver 也許會遇到 PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mongodb.so' - /usr/lib64/php