"MongoDB" Management Command collection

Source: Internet
Author: User
Tags dba

[TOC]

Slow query
// 开启2000毫秒以上的慢查询记录db.setProfilingLevel(1,2000)// 查看最近5条慢查询show profile// 按照慢查询执行时间倒序查询db.system.profile.find().sort({‘millis‘:-1}).pretty// 查看查询计划db.Sync_Log.find({"$and":[{"mbid" :{$eq 7542163}},{‘t‘:{$gte:2333}}]}).explain()// 关闭慢查询记录db.setProfilingLevel(0)
Task management stops queries that exceed a certain time
db.currentOp().inprog.forEach(function(item){if (item.secs_running > 1000 ) db.killOp(item.opid);})
Stop a query on a table
db.currentOp().inprog.forEach(function(item){if (item.ns == "dbA.tbA")db.killOp(item.opid)})
Find some kind of task
db.currentOp().inprog.forEach(function(item){if (item.op=="query"){print(item.opid,item.op);}})
Another way of thinking about the task of viewing
db.currentOp(    {$and :[        {ns:{$ne:‘local.oplog.rs‘}},        {ns:{$ne:‘local.replset.minvalid‘}},        {ns:{$ne:‘admin.$cmd‘}},        {ns:{$ne:‘‘}}]    })
Replica set management modifies host names
cfg = rs.conf()cfg.members[0].host = "xxxhost: 20000"cfg.members[1].host = "yyyhost: 20001"cfg.members[2].host = "zzzhost: 20002"rs.reconfig(cfg)
Shard Management Modify Primary Shard

When a MongoDB shard cluster creates a database, the system picks a node with the largest number of available empty nodes as its default node.

db.runCommand({"movePrimary": "test", "to": "shard0000"})
Manually migrating a collection's data blocks

Purpose: Pre-migrating data when a node is required to be offline

sh.moveChunk("dbA.collectionB", { collC: "53187" }, "shard0019")

If an error occurs

"MongoDB" Management Command collection

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.