Monfodb is an open source document database, providing common performance, high availability, automatic expansion, etc.
A record in MongoDB is a document that is a pair structure of fields and values. The MongoDB document resembles a JSON object, and the value of the field can contain an array of other documents, arrays, and documents. Records are organized into collection, equivalent to tables. Refer to the following figure:
The advantages of working with documents are:
Documents correspond to the native data objects in many programming languages
inline documents and arrays reduce join overhead
Dynamic schema supports smooth polymorphism
Key Features:
Performance:
MongoDB provides high performance data persistence. Especially:
Support for embedded data model reduces database system I/O
Index supports quick queries and embedded documents and arrays can contain keys
High Availability:
MongoDB provides high availability is replica sets
Auto Fail switch
Data redundancy
Replica set is a set of MONGODB servers that maintain the same dataset, provide redundancy, and increase data availability.
Automatic Horizontal expansion:
Horizontal scaling is the kernel feature of MongoDB.
Automatically share distributed data on a cluster
Replica sets can provide final consistency reading for applications with low latency and high throughput.
Installation:
0
Environment
[Root@host2 ~]# Uname-a
Linux host2 2.6.32-504.3.3.el6.x86_64 #1 SMP Wed Dec 01:55:02 UTC 2014 x86_64 x86_64 x86_64 gnu/linux
[Root@host2 ~]# Cat/etc/issue
CentOS Release 6.5 (Final)
Kernel \ r \m
1
Download:
Curl-o http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.7.tgz
2
[Root@mgdbsvr mongodb]# TAR-ZXVF mongodb-linux-x86_64-2.6.7.tgz
Mongodb-linux-x86_64-2.6.7/readme
Mongodb-linux-x86_64-2.6.7/third-party-notices
mongodb-linux-x86_64-2.6.7/gnu-agpl-3.0
Mongodb-linux-x86_64-2.6.7/bin/mongodump
Mongodb-linux-x86_64-2.6.7/bin/mongorestore
Mongodb-linux-x86_64-2.6.7/bin/mongoexport
Mongodb-linux-x86_64-2.6.7/bin/mongoimport
Mongodb-linux-x86_64-2.6.7/bin/mongostat
Mongodb-linux-x86_64-2.6.7/bin/mongotop
Mongodb-linux-x86_64-2.6.7/bin/mongooplog
Mongodb-linux-x86_64-2.6.7/bin/mongofiles
Mongodb-linux-x86_64-2.6.7/bin/bsondump
Mongodb-linux-x86_64-2.6.7/bin/mongoperf
Mongodb-linux-x86_64-2.6.7/bin/mongod
Mongodb-linux-x86_64-2.6.7/bin/mongos
Mongodb-linux-x86_64-2.6.7/bin/mongo
[Root@mgdbsvr mongodb]#
3
Copy of the planned folder
[Root@mgdbsvr mongodb]# MV Mongodb-linux-x86_64-2.6.7/opt/mongodb
4
Configure Environment variables
[Root@mgdbsvr ~]# Vi. Bash_profile
Path= $PATH:/opt/mongodb/bin
5
folder where data resides
[Root@mgdbsvr mongodb]# mkdir dbdata
6
Enable user Mongod to read and write data in the folder
[Root@mgdbsvr mongodb]# useradd-r Mongod
[Root@mgdbsvr mongodb]# chown Mongod:mongod dbdata/
7
Start
[Root@mgdbsvr mongodb]# Mongod--dbpath dbdata
2015-02-13t17:56:23.704+0800 [Initandlisten] MongoDB starting:pid=2035 port=27017 dbpath=dbdata 64-bit host=mgdbsvr
2015-02-13t17:56:23.708+0800 [Initandlisten] DB version v2.6.7
2015-02-13t17:56:23.708+0800 [Initandlisten] git version:a7d57ad27c382de82e9cb93bf983a80fd9ac9899
2015-02-13t17:56:23.708+0800 [Initandlisten] Build info:linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri 3 21:39:27 UTC 2014 x86_64 boost_lib_version=1_49
2015-02-13t17:56:23.708+0800 [Initandlisten] Allocator:tcmalloc
2015-02-13t17:56:23.708+0800 [Initandlisten] options: {storage: {dbpath: ' Dbdata '}}
2015-02-13t17:56:23.738+0800 [Initandlisten] Journal Dir=dbdata/journal
2015-02-13t17:56:23.741+0800 [Initandlisten] recover:no journal files present, no recovery needed
2015-02-13t17:56:24.520+0800 [Initandlisten] preallocateisfaster=true 13.46
2015-02-13t17:56:25.273+0800 [Initandlisten] Preallocateisfaster=true 12.5
2015-02-13t17:56:27.166+0800 [Initandlisten] preallocateisfaster=true 8.76
2015-02-13t17:56:27.166+0800 [Initandlisten] preallocateisfaster check took 3.423 secs
2015-02-13t17:56:27.167+0800 [Initandlisten] preallocating a journal file dbdata/journal/prealloc.0
2015-02-13t17:56:30.089+0800 [Initandlisten] File preallocator progress:891289600/1073741824 83%
2015-02-13t17:56:31.216+0800 [Initandlisten] preallocating a journal file dbdata/journal/prealloc.1
2015-02-13t17:56:34.070+0800 [Initandlisten] File preallocator progress:629145600/1073741824 58%
2015-02-13t17:56:35.779+0800 [Initandlisten] preallocating a journal file dbdata/journal/prealloc.2
2015-02-13t17:56:38.054+0800 [Initandlisten] File preallocator progress:859832320/1073741824 80%
2015-02-13t17:56:39.630+0800 [Initandlisten] allocating new ns file Dbdata/local.ns, filling with zeroes ...
2015-02-13t17:56:39.762+0800 [Fileallocator] Allocating new datafile dbdata/local.0, filling with zeroes ...
2015-02-13t17:56:39.763+0800 [fileallocator] Creating directory Dbdata/_tmp
2015-02-13t17:56:39.797+0800 [Fileallocator] Done allocating datafile dbdata/local.0, SIZE:64MB, took 0.002, secs
2015-02-13t17:56:39.832+0800 [Initandlisten] Build Index On:local.startup_log properties: {v:1, key: {_id:1}, Name: "_id_", ns: "Local.startup_log"}
2015-02-13t17:56:39.855+0800 [Initandlisten] added index to empty collection
2015-02-13t17:56:39.894+0800 [initandlisten] command Local. $cmd command:create {create: "Startup_log", size:10485760, Capped:true} ntoreturn:1 keyupdates:0 numyields:0 reslen:37 281ms
2015-02-13t17:56:39.897+0800 [Initandlisten] waiting for connections on port 27017
8
Connect, simple to use
[Root@mgdbsvr ~]# MONGO
MongoDB Shell version:2.6.7
Connecting To:test
#查看当前数据库
> DB
Test
#切到数据库 MyDB
> Use MyDB
Switched to DB MyDB
> DB
MyDB
#用javascript创建两个文档
> j = {name: "MONGO"}
{' name ': ' MONGO '}
> k = {x:3}
{"X": 3}
#创建mydb数据库和testdata Collection
> Db.testdata.insert (j)
Writeresult ({"ninserted": 1})
> Db.testdata.insert (k);
Writeresult ({"ninserted": 1})
> Show Collections
System.indexes
TestData
> Db.testdata.find ()
{"_id": ObjectId ("54ddd717d692cfe0bd20d983"), "name": "MONGO"}
{"_id": ObjectId ("54ddd728d692cfe0bd20d984"), "X": 3}
>
>
> Show DBS
Admin (empty)
Local 0.078GB
MyDB 0.078GB
>
> Use HAHADB
Switched to DB hahadb
> Show DBS
Admin (empty)
Local 0.078GB
MyDB 0.078GB
> DB
Hahadb
> j = {name: "MONGO"}
{' name ': ' MONGO '}
> Show DBS
Admin (empty)
Local 0.078GB
MyDB 0.078GB
> Db.testdata.insert (j)
Writeresult ({"ninserted": 1})
> Show DBS
Admin (empty)
HAHADB 0.078GB
Local 0.078GB
MyDB 0.078GB
>
> Use MyDB
Switched to DB MyDB
> Show Collections
System.indexes
TestData
>
> Db.testdata.insert (j)
Writeresult ({"ninserted": 1})
> Db.testdata.find ()
{"_id": ObjectId ("54ddd717d692cfe0bd20d983"), "name": "MONGO"}
{"_id": ObjectId ("54ddd728d692cfe0bd20d984"), "X": 3}
{"_id": ObjectId ("54ddda64d692cfe0bd20d986"), "name": "MONGO"}
> Db.testdata.insert (k)
Writeresult ({"ninserted": 1})
>
>
> Db.testdata.find ()
{"_id": ObjectId ("54ddd717d692cfe0bd20d983"), "name": "MONGO"}
{"_id": ObjectId ("54ddd728d692cfe0bd20d984"), "X": 3}
{"_id": ObjectId ("54ddda64d692cfe0bd20d986"), "name": "MONGO"}
{"_id": ObjectId ("54ddda7dd692cfe0bd20d987"), "X": 3}
>
> Db.testdata.find ({x:3})
{"_id": ObjectId ("54ddd728d692cfe0bd20d984"), "X": 3}
{"_id": ObjectId ("54ddda7dd692cfe0bd20d987"), "X": 3}
>
>
> exit;
[Root@mgdbsvr ~]#
Reference:
docs.mongodb.org/manual/tutorial/install-mongodb-on-linux/
-----------------
Reprint please the Source:
Blog.csdn.net/beiigang