- 
    Type:
Bug
 - 
    Resolution: Duplicate
 - 
    Priority:
Major - P3
 - 
    None
 - 
    Affects Version/s: 3.6.2
 - 
    Component/s: Aggregation Framework
 - 
    None
 - 
    Environment:db.version() --> 3.6.2
OS: MacOS High Sierra 10.13.1 
- 
        ALL
 - 
        
 - 
        None
 
- 
        None
 - 
        None
 - 
        None
 - 
        None
 - 
        None
 - 
        None
 
I was trying to use an aggregation pipeline in the following order:
match -> sort -> skip(4) -> limit(2)
In my case: 
1. Match step returned 6 documents
2. Sort step sorts data, but they all have the same value in the sorted column
3. Skip step skips first 4 documents
4. Limit step limits the result to 2 documents. 
I expected to see last 2 documents from the match result, but the query returned 2-nd and 4-th documents from the match result. If I set a limit to 3, then everything works as expected (I receive last 2 documents). The other way to get a correct result is to add an _id : 1 as the last sort column in sort step or exclude sort step at all.
If I use simple chaining like .find().sort().skip().limit() it works correct too.
- duplicates
 - 
                    
SERVER-28195 $skip followed by $limit in aggregation resort & lost records when $sort by equal values
-         
 - Closed
 
 -