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

142
Views
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
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!