MongoDB Linux Installation
Download the latest version of MongoDB, download link: http://www.mongodb.org/dr/fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.2.tgz/download
Enter TAR–XZVF mongodb-linux-x86_64-2.0.2.tgz into the/usr/local/mongodb directory, the following is called the root directory, and then create the Data folder and the log folder under the root directory, Then create a new Mongodb.log file in the log folder, and after you do this, the root directory structure looks like this:
.
|--gnu-agpl-3.0
|--README
|--third-party-notices
|--bin
| |--Bsondump
| |--MONGO
| |--Mongod
| |--Mongodump
| |--Mongoexport
| |--Mongofiles
| |--Mongoimport
| |--Mongorestore
| |--MONGOs
| |--Mongosniff
| |--Mongostat
| '--Mongotop
|--data
'--Log
'--Mongdb.log
Then go to the Bin directory and enter the following command to start the MongoDB server in the background.
./mongod--dbpath=/usr/local/mongodb/data/--logpath=/usr/local/mongodb/log/mongodb.log–logappend &
MongoDB C + + Access
Some preparations for using C + + to access MongoDB:
1. You need to use a pre-compiled libmongoclient.a static library and some corresponding header files.
2. You need to use the Boost library above the 1.34 version.
The LIBMONGOCLIENT.A static library and the corresponding header files are included in the project, and the following are the installation methods for the 1.34.1 version of the Boost library.
1.34.1 version of the Boost library installation method is very simple, just unzip it into a directory, and then add the directory to the library loading path, here we take/usr/local/lib as an example.
Here's how to add a directory to the library load path:
There is a file named. bash_profile under the user root directory. Open the file and add the following command:
Export Ld_library_path=/usr/local/lib
After you join the directive, enter the source. Bash_profile in the console.
Here is a sample test that has the following directory structure:
.
|--bin
|--doc
|--include
| '--MONGO
| |--Client
| | |--connpool.h
| | |--dbclient.h
| | |--Gridfs.h
| | |--model.h
| | |--parallel.h
| | '--Syncclusterconnection.h
| |--DB
| | |--background.h
| | |--btree.h
| | |--client.h
| | |--Clientcursor.h
| | |--cmdline.h
| | |--Commands.h
| | |--Concurrency.h
| | |--Curop.h
| | |--Cursor.h
| | |--database.h
| | |--Db.h
| | |--Dbhelpers.h
| | |--dbmessage.h
| | |--diskloc.h
| | |--extsort.h
| | |--Filever.h
| | |--index.h
| | |--instance.h
| | |--introspect.h
| | |--jsobj.h
| | |--Jsobjmanipulator.h
| | |--Json.h
| | |--Lasterror.h
| | |--Matcher.h
| | |--minilex.h
| | |--module.h
| | |--namespace.h
| | |--nonce.h
| | |--pdfile.h
| | |--Query.h
| | |--Queryoptimizer.h
| | |--queryutil.h
| | |--rec.h
| | |--reccache.h
| | |--reci.h
| | |--recstore.h
| | |--repl.h
| | |--replset.h
| | |--resource.h
| | |--Scanandorder.h
| | |--Security.h
| | '--update.h
| |--stdafx.h
| |--Targetver.h
| '--Util
| |--Allocator.h
| |--Array.h
| |--assert_util.h
| |--atomic_int.h
| |--background.h
......
| |--optime.h
| |--processinfo.h
| |--queue.h
| |--sock.h
| |--thread_pool.h
| '--unittest.h
|--Lib
| '--LIBMONGOCLIENT.A
'--src
'--main.cpp
The code for Main.cpp is as follows:
It is then compiled under the SRC directory with the following compiler instructions:
g++-O. /bin/main main.cpp-i. /include/mongo. /lib/libmongoclient.a-lboost_thread-mt-lboost_filesystem-mt-lboost_program_options
Build the executable file in the bin directory after the compilation is complete main
Enter./main execution with the following results:
Then look at the local MongoDB server and the results are as follows:
The test passed successfully.
MongoDB Linux C + + development environment Research