EDIT: Basically I'm looking for some hints on how to understand what background operations are running on my MongoDB instance and possibly reduce/disable them when necessary so they don't interfere with running tests. I've tried mongostat
and mongotop
but haven't found anything with them that helped me understand what background operations are running and what is initiating them. db.currentOp()
consistently returns an empty array when run before I start running my tests.
I regularly run tests while developing with node (mocha, cucumber). Since yesterday, about 25% of the time server initialization fails trying to connect to mongodb with the following error:
**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)
We use pow-mongodb-fixtures to clear the db and fill it with some basic data before running tests, which is where this is happening. AFAIK nothing major changed when this started happening. Any ideas where I can even start researching the source of this error?
Well I'm not going to mark this as the answer because I was looking for a way to monitor what is happening and figure out the issue through mongo db. Nevertheless, I did figure out the problem. Not the most helpful solution in the world, but it turned out that we were asynchronously starting the server, which would run all the mongoose schemas and thereby check/recreate all indexes, and more or less simultaneously I was running the fixtures code to clear my collections.
In short, don't try to delete collections while creating indexes on them :)
Your friend in this case would be:
db.currentOp(true)
Specifying true includes operations on idle connections and system operations.
See here: https://docs.mongodb.org/manual/reference/method/db.currentOp/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With