[SERVER-11877] mongos query results include sort fields implicitly excluded by projection Created: 27/Nov/13  Updated: 24/Nov/15  Resolved: 24/Nov/15

Status: Closed
Project: Core Server
Component/s: Querying, Sharding
Affects Version/s: 2.5.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-19355 Support skip, limit, and projection i... Closed
Related
related to SERVER-10831 Sorting doesn't work if sort key excl... Closed
Operating System: ALL
Participants:

 Description   

When mongos is asked to perform on a sort on a field that is implicitly projected out (e.g. by an inclusion of another field), mongos does not strip out the field as expected.

Reproduce with the following ("collection" can be either sharded or unsharded):

mongos> db.collection.insert({_id:9, a:"hello"})
mongos> db.collection.find({},{_id:1})
{ "_id" : 9 }
mongos> db.collection.find({},{_id:1}).sort({a:1})
{ "_id" : 9, "a" : "hello" }

It is not expected that "a" is returned in the results for the sorted query above. Running the same query when connected directly to the shard returns the correct results:

> db.collection.find({},{_id:1})
{ "_id" : 9 }
> db.collection.find({},{_id:1}).sort({a:1})
{ "_id" : 9 }



 Comments   
Comment by J Rassi [ 24/Nov/15 ]

This has been fixed with the rewrite of the mongos query path. As of SERVER-19355, mongos now uses the "sortKey" $meta projection in order to retrieve the sort key for each document, which is not exposed to the user.

Closing as a dup of SERVER-19355.

Generated at Thu Feb 08 03:26:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.