Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda