Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda