MongoDB installation configuration and simple use process

Source: Internet
Author: User

MongoDB is a product between a relational database and a non-relational database, and is the most versatile and most like relational database in a non-relational database. The data structure he supports is very loose and is a JSON-like Bjson format, so you can store more complex data types. MONGO's biggest feature is that the query language he supports is very powerful, and its syntax is a bit like an object-oriented query language that almost implements most of the functionality of a relational database single-table query, and also supports indexing of data.

MongoDB is one of the NoSQL, and as more and more companies use the product, has begun to gradually replace the status of some high-performance queries.


It is characterized by high performance, easy to deploy, easy to use, and easy to store data. The main features are:

For collection storage, easy to store data for object types.

Mode of freedom.

Supports dynamic queries.

Supports full indexes, including internal objects.

Support Queries.

Supports replication and recovery.

Use efficient binary data storage, including large objects such as video.

Automatically process fragmentation to support scalability at the cloud level

Supports multiple languages such as ruby,python,java,c++,php.

File storage format is Bson (an extension of JSON)

Accessible over the network

######### installation Process ##########

1, go to the website of MongoDB Direct download, here we download the version of 3.0.3.

[[email protected] yunwei]# tar zxf mongodb-linux-x86_64-3.0.3.gz -c /usr/ local/[[email protected] yunwei]# cd /usr/local[[email protected] local]#  Ln -s mongodb-linux-x86_64-3.0.3 mongodb[[email protected] local]# lllrwxrwxrwx    1 root root   26 jun 15 10:26 mongodb - > mongodb-linux-x86_64-3.0.3[[email protected] local]# cd mongodb[[email  protected]ster mongodb]# lltotal 68drwxr-xr-x 2 root root  4096  Jun 15 10:26 bin-rw-r--r-- 1 1046 1046 34520 may 12 05:35  GNU-AGPL-3.0-rw-r--r-- 1 1046 1046  1359 May 12 05:35  Readme-rw-r--r-- 1 1046 1046 22660 may 12 05:35 third-party-notices

The Mongod under the bin is the service-side process of MongoDB, MONGO is its client, and other commands are used for MongoDB for other purposes such as MongoDB file export.

2, start MongoDB, to first establish a good MongoDB storage data files and log files directory:

[[email protected] mongodb]# pwd/mysqldata/mongodb[[email protected] mongodb]# lltotal 8drwxr-xr-x 2 root root 4096 June 15  14:27 db# Storage of DB data drwxr-xr-x 2 root root 4096 June 14:28 log# store mongodb log files [[email protected] mongodb]# CD Log[[email Protected] log]# Pwd/mysqldata/mongodb/log[[email protected] log]# lltotal 4-rw-r--r--1 root root 2440 June 15:06 Mong odb.log-rw-r--r--1 root root 0 June 15:05 mongodb.log.2015-06-15t07-06-06

3, in the MongoDB installation directory under the bin using Mongod to start MongoDB;

[[email protected] mongodb]# cd bin/[[email protected] bin]# lltotal  116340-rwxr-xr-x 1 1046 1046  4305912 may 12 05:35  Bsondump-rwxr-xr-x 1 1046 1046 11694552 may 12 05:43 mongo-rwxr-xr-x  1 1046 1046 22349960 may 12 05:43 mongod-rwxr-xr-x 1 1046  1046  6199144 may 12 05:35 mongodump-rwxr-xr-x 1 1046 1046   6001840 May 12 05:35 mongoexport-rwxr-xr-x 1 1046 1046   5956232 May 12 05:35 mongofiles-rwxr-xr-x 1 1046 1046   6211952 may 12 05:35 mongoimport-rwxr-xr-x 1 1046 1046  5686856  May 12 05:35 mongooplog-rwxr-xr-x 1 1046 1046 22129448 May  12 05:43 mongoperf-rwxr-xr-x&Nbsp;1 1046 1046  6332464 may 12 05:35 mongorestore-rwxr-xr-x 1  1046 1046 10552760 May 12 05:43 mongos-rwxr-xr-x 1 1046  1046  5909928 may 12 05:35 mongostat-rwxr-xr-x 1 1046 1046   5769944 may 12 05:35 mongotop[[email protected] bin]# ./mongod - -help#  can use--help to view the Help documentation for MONGODB [[email protected] bin]# ./mongod --dbpath=/mysqldata/ mongodb/db/ --logpath=/mysqldata/mongodb/log/mongodb.log &[[email protected] log]#  netstat -lanp | grep 27017tcp        0       0 0.0.0.0:27017                0.0.0.0:*                    listen      2661/./mongod        unix  2      [ ACC ]      stream     listening     2420077 2661/./mongod        /tmp/mongodb-27017.sock

4, you can see, started successfully, and now use the MONGO client access to the database, see the following is the start of the success (if there are some warnings do not matter)

[Email protected] bin]#/mongomongodb shell version:3.0.3connecting to:testwelcome to the MongoDB shell. For interactive help, type ' help '. For more comprehensive documentation, seehttp://docs.mongodb.org/questions?  Try the support grouphttp://groups.google.com/group/mongodb-user> show dbs;local 0.078gb> use local;switched to DB    Local> Show tables;startup_logsystem.indexes> Select * from system.indexes;2015-06-15t15:23:16.469+0800 E QUERY Syntaxerror:unexpected identifier>

############ MongoDB use of some commands #############

[[Email protected] bin]# ./mongomongodb shell version: 3.0.3connecting to:  testwelcome to the mongodb shell.> db# View all Databases  local> show  collectionsstartup_logsystem.indexes> use mydb# directly use mydb  can create mydb this database switched  To db mydb> dbmydb> db.user.save ({name: ' Rod ', age:30})   #新增数据 > for (var  i=1;i<=10;i++)  db.user.save ({x:8,y:i})   #遍历插入10条数据 > db.user.find () {  "_id"   :  objectid ("557e8101e23d20a4115e493d"),  "x"  : 8,  "y"  : 1 }{  "_id"  : objectid ("557e8101e23d20a4115e493e"),  "x"  : 8,  "Y"  : 2 }{   "_id"  : objectid ("557e8101e23d20a4115e493f"),  "x"  : 8,  "Y"  : 3  }{  "_id"  : objectid ("557e8101e23d20a4115e4940"),  "x"  : 8,  "Y" &NBSP;:  4 }{  "_ID " : objectid" ("557e8101e23d20a4115e4941"),  "x"  : 8,  "Y"  : 5 }{   "_id"  : objectid ("557e8101e23d20a4115e4942"),  "x"  : 8,  "Y"  : 6  }{  "_id"  : objectid ("557e8101e23d20a4115e4943"),  "x"  : 8,  "Y" &NBSP;:  7 }{  "_id"  : objectid ("557e8101e23d20a4115e4944"),  "x"  : 8,  "Y"  : 8 }{  "_id"  : objectid ("557e8101e23d20a4115e4945"),  "x"  : 8,   "Y"  : 9 }{  "_id"  : objectid ("557e8101e23d20a4115e4946"),  "X" &NBSP;:  8,  "Y"  : 10 }> db.user.find ({y:{$lt: 5})   #查询y小于5的数据 {  "_id" &NBSP;:  objectid ("557e8101e23d20a4115e493d"),  "x"  : 8,  "y"  : 1 }{  "_id"  : objectid ("557e8101e23d20a4115e493e"),  "x"  : 8,  "Y"  : 2 }{   "_id"  : objeCtId ("557e8101e23d20a4115e493f"),  "x"  : 8,  "y"  : 3 }{  "_id" &NBSP;:  objectid ("557e8101e23d20a4115e4940"),  "x"  : 8,  "Y"  : 4 }>  Db.user.findOne ()   #只查询第一条数据 {  "_id"  : objectid ("557e8101e23d20a4115e493d"),  "X" &NBSP;:  8,  "Y"  : 1 }

The use of various commands of MongoDB we can check on the Internet, there is a lot of information, and written in very detailed.

This article is from the "boiled frog with boiling water" blog, please make sure to keep this source http://tanxw.blog.51cto.com/4309543/1662068

MongoDB installation configuration and simple use process

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.