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

136
Visualizações
The $skip and $limit doesn't work as expected in mongodb aggregate

So i started using mongodb aggregate framework few days ago so i implemented a $limit and a $skip method to my project like this :

let content = await dataSources.WarehouseItem.aggregate([
    { $match: {} },
    { $limit: 2 },
    {
      $group: {
        _id: "$productName",
        quantity: { $first: "$quantity" },
      },
    },
  ]);

But this code instead of it returning 2 documents it returns only 1 but when i put 3 it returns 2 and when i put 4 it returns 3 and so on , and the skip method is also isn't working as expected , there is 4 documents inside of this db but it doesn't return 3 when i do this :

let content = await dataSources.WarehouseItem.aggregate([
    { $match: {} },
    { $skip: 1 },
    {
      $group: {
        _id: "$productName",
        quantity: { $last: "$quantity" },
      },
    },
  ]);

it returns the whole 4 documents

about 4 years ago · Juan Pablo Isaza
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