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

327
Visualizações
Speed ​issue and also memory error when querying in Mongo

I have a table that contains over 100,000 records. Server: node.js/express.js. DB: mongo On the client, a table with a pager is implemented. 10 records are requested each time.

When there were 10,000 records, of course, everything worked faster, but now there was a problem with speed and not only.

My aggregation:

import { concat } from 'lodash';
...
let query = [{$match: {}}];
query = concat(query, [{$sort : {createdAt: -1}}]);
query = concat(query, [
    {$skip : (pageNum - 1) * perPage}, // 0
    {$limit : perPage}                 // 10
]);
return User.aggregate(query)
           .collation({locale: 'en', strength: 2})
           .then((users) => ...;

2 cases:

  1. first fetch very slow

  2. when I click to last page I got error:

    MongoError: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.

Please, tell me, I am building the aggregation incorrectly, or is there a problem with memory on the server as the error says and additional nginx settings are needed (another person is engaged in this) or is the problem complex, or perhaps something else altogether?

Added:

I noticed that the index is not used when sorting, although it should be used?

enter image description here

aggregation to execute console.log =>

[
 {
      "$match": {}
 },
 {
      "$lookup": {
           ...
      }
 },
 {
      "$project": {
           ...,
           createdAt: 1,
           ...
      }
 },
 {
      "$match": {}
 },
 {
      "$sort": {
           "createdAt": -1
      }
 },
 {
      "$skip": 0
 },
 {
      "$limit": 10
 }
]

Thanks for any answers and sorry my English :)

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It does say that you've memory limit, which makes sense, considering that you're trying to filter through 100,000 requests. I'd try using return User.aggregate(query, { allowDiskUse: true }) //etc, and see if that helps your issue.

Whilst this isn't the documentation on the Node.js driver specifically, this link summaries what the allowDiskUse option does (or in short, it allows MongoDB to go past the 100MB memory limit, and uses your system storage to temporarily store some information while it performs the query).

over 4 years ago · Santiago Trujillo Relatório
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