Basic management commands for the MongoDB tutorial _mongodb

Source: Internet
Author: User
Tags mongodb mongodb server mongodb tutorial pkill

1. Start and stop MongoDB:

Execute the mongod command to start the MongoDB server. Mongod has many configurable options, we can view all options through Mongod--help, here are just a few of the main options:

Copy Code code as follows:

--dbpath:
By default, the data directory for the database is/data/db. For Windows platforms, if the current executable is located in D disk, the default data directory is D:\data\db. We can use this option to reassign the data directory to the service program. If the current host is running multiple mongod, you must specify a different data directory for each service program, because once the Mongod is successfully started, a Mongod.lock file is created in the data directory that prevents other Mongod process data from being used in the data directory. Such as:
Mongod--dbpath=d:/data2/db

--port
By default, the default port number is 27017. Also, when multiple Mongod services are running concurrently on the same host, you need to specify separate listening ports for them. Such as:
Mongod--port=29017

--fork
Run the MongoDB in a daemon way.

--logpath
Specifies the log output path instead of the output to the command line. If you have write permission to a folder, the system creates it when the file does not exist. It overwrites the existing file and clears all the original log records. If you want to keep the original log, you also need to use the--logappend option. Such as:
/> Mongod--logpath=d:\logdata\mylog.log
All output Going To:d:\logdata\mylog.log
It is important to note that for the above example, the Logdata directory must be manually created earlier, otherwise Mongod will perform a startup failure.

--config
Specifies the configuration file to load various options not specified by the command line. Such as:
Mongod--config=d:\mydb.conf
The sample contents of the configuration file are as follows:
Port = 29017
Fork = True #这里的井号表示注释部分, for fork This command-line option, you need to use true to indicate open.
LogPath = D:\mylog\db.log

In general, we all want to gracefully close the MongoDB server. If the service program is running at the front desk, then direct CTRL + C. If the background, then through the SIGINT and sigterm signal to inform the service program ready to exit, the server after receiving the signal, will be properly scheduled to exit before the data and state save work, such as: The normal shutdown of the current connection, the data in the cache to the disk, and so on. After all this work is done, the server stops normally. Such as:
Copy Code code as follows:

/> Pkill Mongod
/> Pkill-2 Mongod

Remember not to execute the following command directly:
Copy Code code as follows:

/> pkill-9 Mongod

This signal will cause MONGODB server to be forced to quit immediately.
In addition to the above methods, we can also through the MONGO client tools to notify the server normal exit, such as:
Copy Code code as follows:

> Use admin
Switched to DB admin
> Db.shutdownserver ()

2, Server Status monitoring:

Copy Code code as follows:

C:\mine\thirdparty\mongodb\bin>mongostat
Connected to:127.0.0.1
Insert Query Update delete getmore command flushes mapped vsize ...
0 0 0 0 0 1 0 0m 100m ...
0 0 0 0 0 1 0 0m 100m ...
0 0 0 0 0 1 0 0m 100m ...
0 0 0 0 0 1 0 0m 100m ...
0 0 0 0 0 1 0 0m 100m ...
0 0 0 0 0 1 0 0m 100m ...
0 0 0 0 0 1 0 0m 100m ...
0 0 0 0 0 1 0 0m 100m ...

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.