MongoDB (1) Introduction & Installation configuration

Source: Internet
Author: User
Tags auth data structures mkdir mongodb mongodb server mongodb version administrator password mongodb gui

MongoDB Getting Started column

Http://blog.csdn.net/column/details/19681.html
about MongoDB
MongoDB, written by the C + + language, is an open-source NoSQL database system based on distributed file storage, which, under high load, adds more nodes to ensure server performance and is designed to provide scalable, high-performance data storage solutions for Web applications.
MongoDB stores data as a document and data structures consist of key-value (key=>value) pairs. A MongoDB document is similar to a JSON object. Field values can contain other documents, arrays, and array of documents.


MongoDB Home: https://www.mongodb.com
MongoDB Official document: Https://docs.mongodb.com NoSQL and RDBMS MongoDB is a typical NoSQL database that distinguishes MYSQL,ORACLE,DB2 from these traditional relational databases;

Rdbms Nosql
Characteristics -Highly organized structured data
-Structured Query Language (SQL) (SQL)
-Data and relationships are stored in separate tables.
-Data manipulation language, data definition language
-Strict consistency
-Basic services
-represents more than just SQL
-No declarative query language
-No pre-defined pattern
-key-value pair storage, column storage, document storage, graphics database
-final consistency, not ACID properties
-Unstructured and unpredictable data
-Cap theorem
-High performance, high availability and scalability
Follow the principles ACID principle
A (atomicity) atomicity
C (consistency) consistency
I (isolation) Independence
D (Durability) Persistence
Cap principle
Consistency (consistency) (all nodes have the same data at the same time)
Availability (availability) (ensures that each request responds regardless of success or failure)
Delimited tolerance (Partition tolerance) (loss or failure of any information in the system does not affect the continued operation of the system)


The following are the categories and sections of NoSQL that represent:
Column Storage Hbase, Cassandra, hypertable
Document storage MongoDB, CouchDB
Key-value Storage Tokyo cabinet/tyrant, Berkeley DB, Memcachedb, Redis
Diagram Storage NEO4J, FLOCKDB
Object storage Db4o, Versant
XML database Berkeley DB XML, BaseX


The following is a partial SQL concept that corresponds to the MongoDB concept:
SQL Terminology/Concepts MongoDB Terminology/Concepts Explanation/Description
Database Database Database
Table Collection Database Tables/Collections
Row Document Data record lines/documents
Column Field Data fields/Fields
Index Index Index
Table joins Table connection, MongoDB not supported
Primary key Primary key Primary key, MongoDB automatically sets the _id field as the primary key





MongoDB Installation ConfigurationThe following is an example of the MongoDB installation configuration of the Linux environment, which is similar to the operation in the OS X,window environment;
DownloadSelect the appropriate MongoDB version to download, note the Windows version of the mongodb-3.6 MSI installer may appear when the progress bar stuck in the installation situation, you can directly kill the thread, directly start the configuration step, or download the installation version 3.4 MongoDB; Download address : https://www.mongodb.com/download-center?jmp=tutorials&_ga= 2.97410399.1138236154.1518440736-1543170749.1518440736#community

UnzipLinux version is generally downloaded after a compressed package, the package can be extracted to obtain MONGODB running program, assuming that the compression package extracted after the directory mongodb-3.6.2, in order to facilitate startup, the Mongodb-3.6.2/bin directory is generally written to the system PATH variable; 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 to set all the files under MONGODB-3.6.2/group and own;
Start MongoDB ServiceThere are 2 ways to run the MongoDB service, the first is to specify the running parameters directly, the second is to specify the configuration file, which first shows the first;
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,logpath location to run 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 have already written the path variable of the Mongodb-3.6.2/bin to the system path, if there is no need to locate the directory to execute the instruction;

set the administrator passwordMongoDB default does not set the password, in order to set a security setting at least one administrator password, the steps are as follows:
Assad@desktop-assad ~ $ MONGO # login in MongoDB
>show DBS; # Show all existing tables
Admin 0.000GB
Local 0.000GB
> Use admin # using the admin database
Switched to DB admin
> Db.createuser ({User: "Assad", pwd: "mongo123", roles:["root"]}) # Create a user in the admin database
Successfully added User: {"user": "Assad", "roles": ["Root"]}
After that, restart the MongoDB service and start in Auth authentication mode as follows:
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
At this point, if directly logged into the MongoDB service, all database operations will be rejected, need to login with a password:
Assad@desktop-assad ~ $ mongo-u assad-p mongo1994 127.0.0.1:27017/admin # Log in to MongoDB as an administrator
> Show DBS
.....


using a configuration file to start the MongoDB serviceThe above MongoDB boot process parameters are cumbersome, you can write a configuration file from the configuration file to start MongoDB, the following is a sample configuration file:
/etc/mongod.conf
# for documentation of all options, see:
# http://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
Start the MongoDB service from this configuration file:
$ mongod-f/etc/mongod.conf
The parameters in the configuration file are actually explained by MONGO--help;

MongoDB GUI InterfaceMongoDB provides a simple HTTP user interface, if you want to enable this feature, you only need to start with the parameter--rest, as follows:
$ mongod-f
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.