监控MongoDB"后台操作"?

时间:2015-11-19 09:41:59

标签: node.js mongodb mongodb-indexes

编辑: 基本上我正在寻找一些关于如何理解我的MongoDB实例上运行的后台操作的提示,并在必要时减少/禁用它们,这样它们就不会干扰运行测试。我已经尝试了mongostatmongotop,但却找不到任何可以帮助我了解正在运行的后台操作以及启动它们的内容。在我开始运行测试之前,db.currentOp()在运行时始终返回一个空数组。

我在使用node(mocha,cucumber)开发时经常运行测试。从昨天开始,大约25%的服务器初始化尝试连接到mongodb失败,出现以下错误:

**Unhandled rejection MongoError: exception: cannot perform operation: a background operation is currently running for collection** somecollection
    at Function.MongoError.create (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)
    at /somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:793:66
    at bound (domain.js:254:14)
    at runBound (domain.js:267:12)
    at Callbacks.emit (.../node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:94:3)
    at null.messageHandler (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:235:23)
    at Socket.<anonymous> (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:294:20)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20)

我们使用pow-mongodb-fixture来清除db并在运行测试之前填充一些基本数据,这就是发生这种情况的地方。当这种情况开始发生时,AFAIK并未发生重大变化。我甚至可以开始研究这个错误来源的任何想法?

1 个答案:

答案 0 :(得分:4)

在这种情况下你的朋友会是:

db.currentOp(true)

指定true包括对空闲连接和系统操作的操作。

见这里:https://docs.mongodb.org/manual/reference/method/db.currentOp/

相关问题