这个命令可以查看当前系统所有的操作信息,包括 find insert update remove等
db.currentOp(true)
{
"host" : "mongodb:27018",
"desc" : "conn71125",
"connectionId" : 71125,
"client" : "10.10.29.205:46144",
"appName" : "mongoserver",
"clientMetadata" : {
"driver" : {
"name" : "mongo-java-driver",
"version" : "3.8.2"
},
"os" : {
"type" : "Linux",
"name" : "Linux",
"architecture" : "amd64",
"version" : "2.6.32-754.17.1.el6.x86_64"
},
"platform" : "Java/Oracle Corporation/1.8.0_181-b13",
"application" : {
"name" : "mongoserver"
}
},
"active" : true,
"currentOpTime" : "2020-06-02T15:10:56.411+0800",
"opid" : 755826710, 当前操作的ID
"secs_running" : NumberLong(23), 操作运行了多少秒
"microsecs_running" : NumberLong(23086826),操作运行了多少微妙
"op" : "query", 操作的类型是query
"ns" : "md_index_test.crawlCommentDto", 操作的库名 表名
"command" : { 查询语句的基本信息
"find" : "crawlCommentDto",
"filter" : { 过滤的条件
"type" : 3,
"probability" : {
"$gt" : -1
},
"brandId" : NumberLong(139)
},
"sort" : {
"commentDate" : -1
},
"limit" : 4,
"$db" : "md_index_test",
"$readPreference" : {
"mode" : "secondaryPreferred"
}
},
"numYields" : 701,
"locks" : { 锁的相关信息
"Global" : "r",全局的读锁
"Database" : "r", 库级别的读锁
"Collection" : "r" 表级别的读锁
},
"waitingForLock" : false, 是否等待获取锁
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(1404)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(702)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(702)
}
}
}
}
db.currentOp(true).inprog.forEach(
function(opDoc){
if (opDoc.client)
printjson(opDoc.client)
}
)
获取当前操作中已经停止的活动 并且操作行为是query
db.currentOp(true).inprog.forEach(
function(opDoc){
if(!opDoc.active && opDoc.op=='query')
printjson(opDoc)
}
)
获取当前操作中已正在执行的活动 并且操作行为是query
db.currentOp(true).inprog.forEach(
function(opDoc){
if(opDoc.active && opDoc.op=='query')
printjson(opDoc)
}
)
db.killOp(opid) //kill当前的操作 opid为具体的操作id号,当然了,只能kill正在进行中的