MongoDB Installation and visualization tools

Source: Internet
Author: User
Tags mongodb tutorial management studio sql server management sql server management studio robomongo mongo shell robomongo download

MongoDB is a very popular NoSQL, document-oriented database management system, officially: MongoDB, I chose the Enterprise Server (MongoDB 3.2.9) version, installed in the Windows Server 2012 environment.

MongoDB uses Bson objects to store, similar to key-value pairs (key/value) of JSON-formatted types, which correspond to the storage model of the MONGODB database and relational db:

The theoretical basis of a NoSQL database is the CAP theory, which stands for Consistency (strong consistency),Availability (availability), andPartition Tolerance (partition fault tolerance), the distributed Data system can only meet two of these features:

    • C: The system is still in a consistent state after performing an operation. In a distributed system, when the update operation succeeds, all users are able to read the latest value, and such a system is considered strong consistency.
    • A: The operation performed by the user must return a result within a certain period of time. If a timeout occurs, then the operation is rolled back, as did the operation.
    • P: Distributed system is composed of multiple partition nodes, each partition node is a separate Server,p attribute indicates that the system can handle the dynamic join and leave of partition node.

When building a distributed system, you must consider the CAP feature. The traditional relational db, which focuses on CA features, is typically stored on a single server. Distributed storage and processing systems that handle massive amounts of data pay more attention to ap,ap than C, but NoSQL does not completely abandon consistency (consistency), and NoSQL retains the final consistency of the data (eventually consistency). Final consistency means that after the update operation is complete, the user will eventually read the value after the data update, but there will be a certain time window, the user will still read the old data before the update, and after a certain time delay, the data is consistent.

One, set the PATH environment variable

In the Windows environment, MongoDB default installation file storage directory is: C:\Program files\mongodb\server\3.2\bin, click Windows+r, enter cmd, start command Prompt, Go to the installation directory:

Every time you open command prompt you need to enter the installation directory of MongoDB is very troublesome, you can modify the computer environment Variables, right click this pc->properties, click Advanced System Setting->environment Variables, open the Environment Variables form, modify the path system variable, append "C:\Program files\" to the string of the path variable Mongodb\server\3.2\bin ", note between two paths with"; " Segmentation.

Two, get you started.

1. Start the MongoDB instance

After setting the environment variable successfully, create a folder in the C drive, data, to store the MongoDB database files. Then, open a command-line tool, enter Mongod to start the MongoDB instance, and the default listening TCP port is 27017.

Mongod

MongoDB initiates an HTTP server at the same time, listens on 27017 port, if the MongoDB instance installs locally, then enters in the browser: http://localhost:27017/

Mongod is the most core of the whole MONGODB process, responsible for database creation, deletion and other management operations, running on the server side, listening to client requests, providing data services.

2, linking to a MongoDB instance

Do not close the MongoDB instance, open a new command-line tool, enter MONGO, the command starts MONGO Shell,shell will automatically connect to the local (localhost) MongoDB instance, the default port is 27017:

Mongo

The MONGO process is to construct a JavaScript Shell that interacts with the Mongod process to manage the MongoDB database according to the interface provided by Mongod, which is equivalent to SSMS (SQL Server Management Studio). is a tool for managing MongoDB.

3. View the current connected DB

Use the command to view the name of the database being connected

Db
Db.getname ()

4. View the DB and collection in the MongoDB instance

Show Dbsshow Collections
Db.getcollectionnames ()

5, Switch DB

Use Foo

6, create a Users collection in the Foo database, insert a document into the collection

Use Foodb.users.insert ({"name": "Name 1", age:21}) Db.users.find ()

7, Close a MongoDB instance

In the MONGO shell, close the MongoDB instance by executing the following command

Use Admindb.shutdownserver ()

8, help command

Help

DB.HELP () Viewing database-level Help
Db.mycoll.help () Viewing collection-level help

Three, Mongod command common parameters

1, common parameters

Mongod is the main daemon for MongoDB systems, which handles data requests, data access, and background management operations, which must be started to access the MongoDB database.

When starting Mongod, the commonly used parameters are:

    • --dbpath <db_path> : directory where mongodb data files are stored
    • --directoryperdb : Specifies that each database is stored separately in one directory (directory), which is located in the directory specified by--dbpath, and each subdirectory corresponds to a database name. Uses a separate directory to store data for each database. The directories is under the--dbpath directory, and each subdirectory name corresponds to the database name.
    • --logpath <log_path> : Specify Mongod log file
    • --fork : Run the service in deamon form later
    • --journal : Start logging function to reduce the recovery time of a single machine failure by saving the operation log
    • --config (or-F) <config_file_path>: Configuration file to specify runtime options
    • --bind_ip <ip address> : Specify the binding IP address of the external service
    • --port <port> : External Services window
    • --auth : Enable authentication, verify user Rights control
    • --syncdelay<value> : The time the system refreshes disk, in second, default is 60s
    • --replset <setname> : Starting Mongod as a replica set, the identity of the replica set is SetName

How to start the 2,mongodb

2.1 Started by command, the default dbpath is C:\data\db

Mongod--dbpath=c:\data\db

2.2 Starting with the configuration document

Writes the Mongod command parameter to the configuration document, starting with the parameter-F

Mongod-f C:\data\db\mongodb_config.config

2.3 Start in daemon mode

When the process to start MongoDB shuts down, MongoDB then shuts down and only needs to use the--fork parameter to enable MongoDB to start in the daemon process.

Mongod-fork

3. View the startup parameters of the Mongod

Db.servercmdlineopts ()

Four, MONGO command common parameters

MONGO is an interactive JS shell that provides a powerful JS environment that provides an interface for DBA management Mongodb,developer querying MongoDB data. Interacting with MONGO Shell and MongoDB, querying and modifying MongoDB databases, managing MONGODB databases, maintaining MongoDB replica sets and Shard clusters, is a very powerful tool.

When starting the MONGO shell, the commonly used parameters are:

    • --nodb: prevents MONGO from connecting to the DB instance at startup;
    • --port <port> : Specifies that the MONGO is connected to the Mongod listening TCP port, the default port value is 27017;
    • --host : Specifies the server that Mongod runs, and if this parameter is not specified, MONGO attempts to connect to a Mongod instance that is running on-premises (localhost);
    • <db address>: Specify the database to which the MONGO is connected
    • --username/-u <username> and --password/-p <password>: Specify the account and password to access the MongoDB database, only when the authentication is passed, the user can access the database;
    • --authenticationdatabase <dbname>: Specifies the database in which the user is created, and when the user is created in which database, the database is the user's authentication Database;

Five, MongoDB visualization tool

1, recommended Robomongo

Robomongo is open source, free mongodb management tool,: Robomongo download

2,mongobooster

Support MongoDB 3.2 version, personal use free, for commercial charges,: Mongobooster download

Six, learn MongoDB

1, recommended to learn MongoDB books

Animal book "MongoDB authoritative Guide-second Edition", very classic

2, learn about MongoDB's Official Handbook: MongoDB Manual

3. Getting Started with MongoDB tutorial : MongoDB Tutorial

Reference Documentation:

Mongod

Mongo

MongoDB Installation and visualization tools

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.