2016-03-29 91 views

回答

1

db.currentOp()命令應該讓您更深入地瞭解由於當前正在運行的操作而導致的鎖定。

下面是命令的輸出示例:

在查詢:

{ 
    "locks": {"^myDB": "R"}, 
    "ns": "myDB.bar", 
    "op": "query", 
    "opid": 1349152, 
    "query": {"test": 1}, 
    "secs_running": 15, 
    "waitingForLock": true 
} 

上更新:

{ 
    "locks": { 
     "^": "w", 
     "^local": "W", 
     "^myDB": "W" 
    }, 
    "ns": "myDB.bar", 
    "op": "update", 
    "opid": 1344808, 
    "query": {}, 
    "secs_running": 53, 
    "waitingForLock": false 
    } 

我沒有測試過,但這樣的事情應該得到的收藏鎖具:

db.currentOp(
    { 
     $and: [ 
      {"waitingForLock" : true}, 
      {"ns" : "mydb.mycoll"} 
     ] 
    } 
) 

來源:http://blog.mlab.com/2014/02/mongodb-currentop-killop/

+1

更多信息,請訪問Collection locks我想這可能做的伎倆 - 是我發現的爲好。謝謝! – silviud

0

試着看一下:

"locks" : { 
    "Global" : { 
     "acquireCount" : { 
      "r" : NumberLong(5776), 
      "w" : NumberLong(14), 
      "W" : NumberLong(4) 
     } 
    }, 
    "Database" : { 
     "acquireCount" : { 
      "r" : NumberLong(2872), 
      "w" : NumberLong(1), 
      "R" : NumberLong(7), 
      "W" : NumberLong(13) 
     } 
    }, 
    "Collection" : {  <-------------- see collection locks 
     "acquireCount" : { 
      "r" : NumberLong(2735) 
     } 
    }, 

對於在MongoDB的網站