Your Site Title

mongodb stop old openration

当客户端断开连接时, 如果是aggregations 和 find操作, 则会自动停止该操作; 如果是写操作, 那么会继续执行; 见https://www.mongodb.com/docs/drivers/node/current/faq/#what-happens-to-running-operations-if-the-client-disconnects- 如果是前端取消操作, 或者重新开始新的操作在FastAPI中, 不会中止之前的操作, 所以不会中止之前的MongoDB操作;

手动停止MongoDB操作

使用db.currentOp()方法可以查看当前正在执行的MongoDB操作; 使用db.killOp(<opId>)方法可以手动停止MongoDB操作;

需要关注哪些查询操作需要手动停止, 当查询之前识别出该操作是否已经存在, 如果存在就停止该操作, 再重新开始.

问题1: 怎么识别出查询操作, 需要研究db.currentOp()返回, 看能不能对应特定的查询操作; 问题2: 怎么识别出不同用户可以有相同的查询操作;

db.currentOp 返回

{
  "inprog": [
    {
      "opid": 12345,
      "active": true,
      "secs_running": 45,
      "microsecs_running": 45000000,
      "op": "query",
      "ns": "mydb.mycollection",
      "command": {
        "find": "mycollection",
        "filter": {
          "status": "pending"
        }
      },
      "client": "192.168.0.1:56789",
      "clientMetadata": {
        "application": {
          "name": "myApp"
        },
        "driver": {
          "name": "nodejs",
          "version": "3.6.4"
        },
        "os": {
          "type": "Linux",
          "name": "Ubuntu",
          "architecture": "x64",
          "version": "18.04"
        }
      },
      "connectionId": 789,
      "waitingForLock": false,
      "numYields": 2,
      "locks": {},
      "lockStats": {
        "Global": {
          "acquireCount": {
            "r": 1
          }
        }
      },
      "planSummary": "COLLSCAN",
      "host": "myserver:27017",
      "desc": "conn",
      "threadId": "139692736116480",
      "lsid": {
        "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
      },
      "txnNumber": 1,
      "readConcern": {
        "level": "local"
      },
      "writeConcern": {
        "w": "majority"
      }
    }
  ]
}

Reference