Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
MongoDB suddenly stop responding because of background processes

Our mongo DB suddenly stops responding to any request and throws error messages like:

 MongoError: cannot perform operation: a background operation is currently running for collection demo2.users
     at MessageStream.messageHandler (....../node_modules/mongodb/lib/cmap/connection.js:268:20)
     at MessageStream.emit (events.js:315:20)
     at processIncomingData (...../node_modules/mongodb/lib/cmap/message_stream.js:144:12)
     at MessageStream._write (....../node_modules/mongodb/lib/cmap/message_stream.js:42:5)
     at writeOrBuffer (internal/streams/writable.js:358:12)
     at MessageStream.Writable.write (internal/streams/writable.js:303:10)
     at Socket.ondata (internal/streams/readable.js:719:22)
     at Socket.emit (events.js:315:20)
     at addChunk (internal/streams/readable.js:309:12)
     at readableAddChunk (internal/streams/readable.js:284:9)
     at Socket.Readable.push (internal/streams/readable.js:223:10)
     at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
   ok: 0,
   code: 12587,
   codeName: 'BackgroundOperationInProgressForNamespace'
}

This error comes out from a connection to mongo:

The operation issued by my application is just a connection to the database:

MongoClient.connect(mongoUrl, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
      ...confOptions,
    })
      .then(async client => {
        return client;
      })
      .catch(err => {

        // And here is where the error comes
        console.log(err);
        return null;
      })

We are using MongoDB driver with node.js. MongoDB and node.js are on the same server (Ubuntu Linux 20.04.2)

For reusing the mongo connections we use the npm generic-pool library, and only when we start the server we setup at the beginning all the indexes and the collections with the commands:

  const existingCollection = await mongo.db(databaseName).listCollections({ name }).next();
  if (existingCollection) {
    await mongo.db(databaseName).command({
      collMod: name,
      validator: { $jsonSchema: schema },
      validationLevel: 'strict',
      validationAction: 'error',
    });
  } else {
    await mongo.db(databaseName).createCollection(name, {
      validator: { $jsonSchema: schema },
      validationLevel: 'strict',
      validationAction: 'error',
    });
  }

and ensuring indexes with

  await mongo.db(databaseName).collection(collectionName).createIndex({
    clientNumber: 1,
  }, { unique: true });

But it looks like mongo starts suddenly to make indexing, validations, and other background operations that lock everything - this happens mostly after few days of a running the server.

The only way mongo starts again to respond is to restart it.

Has anyone any idea what could be the cause of this? Or is there any way to stop any locking background operations of mongo?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!