question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

aggregate with skip can't work

See original GitHub issue

Hi, guys, please help me out, thank you very much!

Schema

ReportSchema = new Schema
  user:type:Schema.ObjectId,ref:'User',index:sparse:true
  report:[
    qid:type:Schema.ObjectId,ref:'Question'
    value:Schema.Types.Mixed
    remark:String
  ]
  created_at:Date

Aggregate when skip=0 works fine, but when skip!=0, I got nothing. I’m sure there’re pages data.

Report.aggregate()
    .unwind('report')
    .match('report.qid':new ObjectId(data.qid))
    .project(
      value:'$report.value'
      remark:'$report.remark'
      user:'$user'
    )
    .sort('created_at':-1)
    .limit(limit)
    .skip(skip)
    .exec (err, result)->

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6

github_iconTop GitHub Comments

15reactions
mani95lisacommented, May 16, 2014

I resolved this to make skip before limit, is it a bug?

.skip(skip)
.limit(limit)
5reactions
vkarpov15commented, May 16, 2014

@mypawdesign is right. In aggregate, $limit limits the number of documents sent to the next aggregation state, and $skip skips the first N documents, so if $skip is after $limit and $skip >= $limit, you won’t get any results. In short, this is expected behavior in MongoDB.

Read more comments on GitHub >

github_iconTop Results From Across the Web

$skip and $limit in aggregation framework - Stack Overflow
In aggregate, $limit limits the number of documents sent to the next aggregation state, and $skip skips the first N documents, so if...
Read more >
Doubt about order or SORT, SKIP, LIMIT when using ...
Hi everyone, I have some doubt about the order of $sort $skip and $limit in the aggregation framework: In the course “MongoDB for...
Read more >
Can you sort, skip, and limit on an aggregate function? - Reddit
Yes aggregate pipelines can have sort, skip and limit stages.
Read more >
MongoDB - Aggregation Pipeline Stages: $skip, $limit
In this video, shows you how to use Aggregation Pipeline Stages: $ skip, $limit. ... Your browser can't play this video.
Read more >
AGGREGATE function - Microsoft Support
The AGGREGATE function can apply different aggregate functions to a list or database with the option to ignore hidden rows and error values....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found