Mongodb brief introduction and installation


Introduction to mongodb

MongoDBIt’s a kind ofNoSQLDatabase, it’s indata storage In the form ofMySQLThis kind ofrelational databaseThere are essential differences.MongoDBThe basic object of storage isDocumentSo we call it a kind ofDocument database, and theaggregateIt is composed ofCollection。 AndSQLThe conceptual analogy of,CollectionCorresponding toTableandDocumentCorresponding toRowDocumentUse aBSON(Binary JSON)Structure,JSONEveryone is familiar with it, like this.
Mongodb brief introduction and installation

Mongodb application scenarios

  • Game scene: UsingMongoDBStore game user information, user equipment, points, etc. are directly stored in the form of embedded documents, easy to query and update

  • Logistics scenario: UsingMongoDBThe order information is stored, and the order status is constantly updated during the delivery process toMongoDBEmbedded array to store, a query can read all the changes in the order

  • Social scene: UsingMongoDBStorage and storage of user information, as well as the user published information of the circle of friends, through the geographic location index to achieve the nearby people, places and other functions

  • IOT scenarios: UsingMongoDBStore the information of all connected intelligent devices, as well as the log information reported by the devices, and conduct multi-dimensional analysis on these information

  • Live video: UsingMongoDBStore user information, gift information, etc

Mongodb installation

MongoDBThe installation method of is relatively simple, becauseSource code installationIt’s troublesome. Our original intention is to learnMongoDBandyumIn order to make it more convenient to learn now, this paper uses Yum method to install.


  • VMware version number: 12.0.0

  • CentOS version: 7.0

notes: version 3.4MongoDBNo longer for32Commercial support is provided on Linux and windows platforms. The installed version of this article is 3.4

See yourselfLinuxedition:

uname –a

x86_64express64Bit machine
i686express32Bit machine

  • wholeMongoDB(Community Edition) contains the following software

#Contains mongod daemons and associated configuration and init scripts

#Contains mongos Daemons

#Contains the Mongo shell, which is a command-line client connected to mongodb, allowing users to directly enter NoSQL syntax to manage the database

#Mongodb contains the following tools: data import, export, backup, recovery, etc
  • Create Yum source file

vim /etc/yum.repos.d/mongodb-org-3.4.repo
  • Copy the following to the source file

name=MongoDB Repository

Mongodb brief introduction and installation

  • Start the yum command to start the installation

yum install -y mongodb-org
  • If usedSELinux, must be configuredSELinuxTo allowRed Hat LinuxOn the system (Red Hat Enterprise Linux or CentOS Linux)MongoDB

vim /etc/selinux/config

takeSELINUXValue todisabled
Mongodb brief introduction and installation

  • Start mongodb (the default connection port of mongodb server is27017)

#Centos6 starts
$ service mongod start

#Centos7 starts
$ systemctl start mongod
  • Check to see if it starts

netstat -tlnup|grep mongod
  • Check whether it is occupied27017Port number

netstat -tlnup|grep 27017
  • Other control commands

#Stop mongodb service
$ service mongod stop

#Restart mongodb
$ service mongod restart
  • Set boot up

chkconfig mongod on
  • Find mongodb client

find / -name mongo

Mongodb brief introduction and installation

  • Connect client


Enter the test commandshow dbsView the current database
Mongodb brief introduction and installation

  • Stop mongodb server
    have access toCtrl + cOr inputexitsign outMongoDBInterface.

notes: EnterMongoDBThe interface appearswarning

Server has startup warnings: 
2017-03-30T06:40:26.039+0800 I CONTROL  [initandlisten] 
2017-03-30T06:40:26.039+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-30T06:40:26.039+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-03-30T06:40:26.039+0800 I CONTROL  [initandlisten] 
2017-03-30T06:40:26.040+0800 I CONTROL  [initandlisten] 
2017-03-30T06:40:26.040+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-03-30T06:40:26.040+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-03-30T06:40:26.040+0800 I CONTROL  [initandlisten] 
2017-03-30T06:40:26.040+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-03-30T06:40:26.040+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-03-30T06:40:26.040+0800 I CONTROL  [initandlisten] 

This is because there is no configurationMongoDBOfSafety functionFor exampleto grant authorizationandAuthentication。 Of course, if it’s just for learning, you can ignore it, but the production environmentConfiguration is required

Recommended Today

Blog based on beego, go blog

Go Blog A beego based development, can quickly create personal blog, CMS system Include functions see Official website of go Demo Update log time function January 23, 2020 New top post function February 2, 2020 New custom navigation function February 4, 2020 New site announcement function February 6, 2020 New link module February […]