-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.4.1
-
Component/s: Aggregation Framework
-
None
-
Environment:targetMinOS: Windows 7/Windows Server 2008 R2
db version v3.4.1
git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
-
ALL
-
Seems, issue exists only when you $sort records having equal value (rating here)
>db.issue.aggregate( [ { '$match': { country: ObjectId("58a1a0bdc98ea02284fe077b"), visible: 1, type: 'customs' } }, { '$sort': { rating: -1 } }, { '$project': {_id:1}} ]);
{ "_id" : ObjectId("58b96e44905c7a279806f8f9") } { "_id" : ObjectId("58b3d25422ad9b04484145f9") } { "_id" : ObjectId("58b3d25d22ad9b04484145fa") } { "_id" : ObjectId("58b3d2d122ad9b04484145fb") } { "_id" : ObjectId("58b9656e905c7a279806f8f6") } { "_id" : ObjectId("58b96575905c7a279806f8f7") } { "_id" : ObjectId("58b96578905c7a279806f8f8") }
> db.issue.aggregate( [ { '$match': { country: ObjectId("58a1a0bdc98ea02284fe077b"), visible: 1, type: 'customs' } }, { '$sort': { rating: -1 } }, { '$project': {_id:1}}, *{ '$skip': 0 }, { '$limit': 5 } * ] );
{ "_id" : ObjectId("58b96e44905c7a279806f8f9") } { "_id" : ObjectId("58b9656e905c7a279806f8f6") } { "_id" : ObjectId("58b96575905c7a279806f8f7") } { "_id" : ObjectId("58b3d25d22ad9b04484145fa") } { "_id" : ObjectId("58b3d25422ad9b04484145f9") }
here we:
- have resorted results
- lost *
{ "_id" : ObjectId("58b3d2d122ad9b04484145fb") }
*
there is no this record on next 5
>db.issue.aggregate( [ { '$match': { country: ObjectId("58a1a0bdc98ea02284fe077b"), visible: 1, type: 'customs' } }, { '$sort': { rating: -1 } }, { '$project': {_id:1}}, { '$skip': 5 }, { '$limit': 5 } ] );
{ "_id" : ObjectId("58b96575905c7a279806f8f7") } { "_id" : ObjectId("58b96578905c7a279806f8f8") }
- is duplicated by
-
SERVER-30338 $sort + $limit optimizer failing in some cases
- Closed
-
SERVER-33107 Incorrect result while using pipeline with skip and limit
- Closed
-
SERVER-43105 Sort operation retun duplicate element
- Closed
- is related to
-
SERVER-27716 mongos 3.2.10, sharded cluster, skip returns duplicates
- Closed
-
SERVER-51498 Sorting on duplicate values causes repeated results with limit and skip
- Closed