MongoDB Operations Common operation

Source: Internet
Author: User

MongoDB Operations Common Operation

Analysis Method:
1. Through the top, free, Iostat, iftop and other tools to see the Linux server average load, CPU utilization, IO, memory, swap, network traffic, etc., first locate the source of the pressure.

2. Analyze MongoDB read-write pressure through mongostat, mongotop, etc. Observe page faults, Connections, queues and other performance indicators.

3. The log has a default record of more than 100ms requests, filters out the overflow query, and then uses the Mtools trace to analyze the slow query statements in the MongoDB log file. If you have a statement problem, you can navigate from the log to the source statement at the time of the performance problem.

Common operations:
1. Restart the service

#service Mongod Restart


2. Trace log Analysis Query

$tail-F/var/log/mongodb/mongod.log


3. Analyze the current read and write status

$mongostat-uxucy-p


4. View database status

>db.serverstatus ()


5. View the number of database connections

>db.serverstatus (). connections


6. View the replication Set status

>rs.status ()


7. Manually downgrade instances

>rs.stepdown (30)


8. View current active query execution

>db.currentop ();


9. Kill the operation that is being performed

>db.killop ("shard3:466404288");


10. Analyzing execution plans for query statements

>db. Product.find ({"_id": 10086}). Explain (). pretty ();


11. Create an index in the background

>db. Product.ensureindex ({"Category": 1, "Status": 1}, {background:1});


12. Data export

$ mongoexport-u xucy-p--authenticationdatabase admin-d dbname-c product-q ' {"adddate": {"$gte": New Date (1445558400000 ), "$lte": New Date (1445731200000)}} '-F "_id,adddate,status"-O Product_20151026.json


13. Data Import

$mongoimport-H 192.168.1.101-u xucy-p-D DBName--authenticationdatabase admin-c datacontent Datacontent_bak.json


14. Database/Table Backup

$ mongodump--authenticationdatabase admin-uxucy-p--db dbname-o/disk1/mongobackup/dbname_fullbackup_20150917


15. Database/Table Recovery

$ mongorestore--authenticationdatabase admin-uxucy-p--db DBName--drop temp_20150909/dbname/


16. Database Authorization

>use dbname >db.createuser ({User: "Peter", pwd: "xxxxxxxx", Roles: [        {role: "ReadWrite", DB: "DBName"}] }    )


This article is from the SQL Server deep dives blog, so be sure to keep this source http://ultrasql.blog.51cto.com/9591438/1712499

MongoDB Operations Common operation

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.