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"
      }
    }
  ]
}

restart

mongod.conf

for documentation of all options, see:

http://docs.mongodb.org/manual/reference/configuration-options/

where to write logging data.

systemLog: destination: file logAppend: true path: /dev/null

path: /data/mongo_log/mongod.log

quiet: true

Where and how to store data.

storage: dbPath: /data/mongo_data journal: enabled: true

engine:

wiredTiger:

how the process runs

processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo

network interfaces

net: port: 27017 bindIp: 94.246.94.12 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

security: authorization: enabled keyFile: /data/mongodb.key #operationProfiling:

replication: replSetName: “rs0”

#sharding:

Enterprise-Only Options

#auditLog:

#snmp:

sudo systemctl stop mongodb

停止 mongod 服务

systemctl stop mongod

mongod –dbpath /data –repair

未持久化的数据, 删除会造成数据不一致

sudo ls -al /data/mongo_data/journal

诊断数据

sudo ls -al /data/mongo_data/diagnostic.data

systemctl start mongod

什么是 oplog

Oplog(Operations Log) 是 MongoDB 副本集用来同步数据的操作日志。

它记录了所有写操作(insert/update/delete),副本集成员会通过 oplog 同步数据。

存储在 local.oplog.rs 集合里。

Reference