MongoDB database introduction & installation configuration, mongodb Database
Apsaradb for MongoDB is a distributed file storage-based open-source NoSQL database system written in C ++. It adds more nodes under high loads, this service guarantees server performance and is designed to provide scalable, high-performance data storage solutions for WEB applications.
MongoDB stores data as a document. The data structure consists of key-value pairs. MongoDB documents are similar to JSON objects. Field Values can contain other documents, arrays, and document arrays.
MongoDB home: https://www.mongodb.com
MongoDB official documents: https://docs.mongodb.comNoSQL and RDBMSMongoDB is a typical NoSQL database, the difference with MySQL, Oracle, DB2 these traditional relational database;
? |
RDBMS |
NoSQL |
Features |
-Highly organized structured data? -Structured Query Language (SQL )? -Data and relationships are stored in separate tables .? -Data manipulation language and Data Definition Language? -Strict consistency -Basic transactions |
-Not only SQL -No declarative query language -No predefined Mode -Key-Value Pair storage, column storage, document storage, and Graphic Database -Final consistency, not the ACID attribute -Unstructured and unpredictable data -CAP theorem? -High performance, high availability and scalability |
Principles |
ACID Principle
- A (Atomicity) Atomicity
- C (Consistency) Consistency
- I (Isolation) Independence
- D (Durability) Persistence
|
CAP principles
- Consistency (all nodes share the same data at the same time)
- Availability (Availability) (Ensure that each request has a response regardless of whether the request succeeds or fails)
- Partition tolerance (loss or failure of any information in the system will not affect the continued operation of the system)
|
The following are the categories and representatives of NoSQL:
Column Storage |
Hbase, Cassandra, Hypertable |
Document Storage |
MongoDB and CouchDB |
Key-value Storage |
Tokyo Cabinet/Tyrant, Berkeley DB, MemcacheDB, Redis |
Graph Storage |
Neo4J, FlockDB |
Object Storage Service |
Db4o, Versant |
Xml Database |
Berkeley db xml, BaseX |
The following are the MongoDB concepts corresponding to some SQL concepts:
SQL terms/concepts |
MongoDB terms/concepts |
Description/Description |
Database |
Database |
Database |
Table |
Collection |
Database tables/Sets |
Row |
Document |
Data Record line/Document |
Column |
Field |
Data Field/Field |
Index |
Index |
Index |
Table joins |
? |
Table connection, not supported by MongoDB |
Primary key |
Primary key |
Primary Key. MongoDB automatically sets the _ id field as the primary key. |
The following uses the MongoDB installation configuration in Linux as an example. The operations in OS X and Window are similar;
DownloadSelect the appropriate MongoDB version for download. Note window? Version? Mongodb-3.6 msi installer may be installed when the progress bar Stuck, at this time you can directly kill the thread, directly start the configuration step, or download the installation of version 3.4 mongodb ;? : Https://www.mongodb.com/download-center? Jmp = tutorials & _ ga = 2.97410399.1138236154.1518316736-1543170749.1518440736 # community
ExtractLinux version is generally downloaded after a compressed package, extract the package to obtain the mongodb running program, assuming that the compressed package unzip to get the directory mongodb-3.6.2; In order to facilitate the start, the mongodb-3.6.2/bin directory is usually written to the system PATH variable; Under the mongodb-3.6.2/create data, logs two directories, respectively for storing data and logs:
assad@DESKTOP-assad:/usr/bin/mongodb-3.6.2$ mkdir data
assad@DESKTOP-assad:/usr/bin/mongodb-3.6.2$ mkdir logs
Then you need? Mongodb-3.6.2/all files under set group and own;
Start mongoDB ServiceThere are two ways to run the mongoDB service. The first is to directly specify the running parameters, and the second is to specify the configuration file. Here we first demonstrate the first one ;?
Assad @ DESKTOP-assad: /usr/bin/mongodb-3.6.2/bin $ mongod -- dbpath =/usr/bin/mongodb-3.6.2/data -- logpath =/usr/bin/mongodb-3.6.2/logs/mongo. log? ? # Specify data and logpath to run the mongodb Service
Connect to mongoDB?
assad@DESKTOP-assad ~ $ mongo
MongoDB shell version v3.6.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.2
......
>
Here I already set? Mongodb-3.6.2/bin? The PATH variable is written to the system PATH. If you do not need to locate the directory, execute this command;
Set administrator passwordMongodb does not set a password by default. To ensure security, at least one administrator password is set. The steps are as follows :?
Assad @ DESKTOP-assad ~ $ Mongo? ? # Log on to mongodb
?
> Show dbs ;? ? ? ? # Show all existing tables
admin ?0.000GB
local ?0.000GB
?
> Use admin? ? ? ? # Use the admin Database
switched to db admin ? ?
?
> Db. createUser ({user: "assad", pwd: "0000123", roles: ["root"]})? ? # Create a user in the admin Database
Successfully added user: { "user" : "assad", "roles" : [ "root" ] }
?
> exit
Then restart the mongoDB service and start it in auth Authentication mode, as shown below :?
assad@DESKTOP-assad:/usr/bin/mongodb-3.6.2/bin$ mongod --dbpath=/usr/bin/mongodb-3.6.2/data --logpath=/usr/bin/mongodb-3.6.2/logs/mongo.log ?--auth
If you log on to the mongoDB service directly, all database operations will be rejected. You need to log on with a password :?
Assad @ DESKTOP-assad ~ $ Mongo-u assad-p limit 1994 127.0.0.1: 27017/admin? # Log on to mongodb as an administrator
> show dbs
.....
Use the configuration file to start the mongoDB ServiceThe above mongoDB startup parameters are cumbersome. You can compile a configuration file to start mongoDB from the configuration file. The following is an example configuration file:
/Etc/mongod. conf?
# for documentation of all options, see:
# https://docs.mongodb.org/manual/reference/configuration-options/
?
# Where and how to store data.
dbpath=/usr/bin/mongodb-3.6.2/data
journal=true
?
# where to write logging data.
logpath=/usr/bin/mongodb-3.6.2/logs/mongod.log
logappend=true
?
# network interfaces
bind_ip=127.0.0.1
port=27017
?
# security
auth=true
Use this configuration file to start the mongodb service :?
$ mongod -f /etc/mongod.conf
The parameters in the configuration file are described by mongo -- help;
MongoDB GUI MongoDB provides a simple HTTP user interface. To enable this function, you only need to set the startup parameter -- rest, as shown below :?
$ mongod -f /etc/mongod.conf --rest
The default Web interface port is 1000 more than the service port. The default port is 28017. Open https: // 127.0.0.1: 28017 in a browser? To open the Management port;
You can also use the MongoDB Client Management Software Robo 3 T, see: https://robomongo.org