aggregate with skip can't work
See original GitHub issueHi, 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:
- Created 9 years ago
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I resolved this to make
skip
beforelimit
, is it a bug?@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.