[SERVER-11173] Difference between querying to mongos and mongod Created: 14/Oct/13  Updated: 10/Dec/14  Resolved: 14/Oct/13

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.4.5
Fix Version/s: None

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

RHEL 5.8


Issue Links:
Related
Operating System: ALL
Steps To Reproduce:

> c = db.test.find(

{title: "shay"}

,

{f:0}

).sort(

{"f":1}

)

{ "_id" : ObjectId("525be8c1513f4b195eaa8d00"), "title" : "shay" }

mongos> c = db.test.find(

{title: "shay"}

,

{f:0}

).sort(

{"f":1}

)
error: {
"$err" : "have to have sort key in projection and removing it",
"code" : 13431
}

Participants:

 Description   

We've encountered an error migrating to sharded environment.
It appear there is a difference between querying mongod and mongos as shown below:
> c = db.test.find(

{title: "shay"}

,

{f:0}

).sort(

{"f":1}

)

{ "_id" : ObjectId("525be8c1513f4b195eaa8d00"), "title" : "shay" }

mongos> c = db.test.find(

{title: "shay"}

,

{f:0}

).sort(

{"f":1}

)
error: {
"$err" : "have to have sort key in projection and removing it",
"code" : 13431
}
I understand (now) that it is not possible to exclude a field from a query and sort on it through mongos (that gets the documents without the fields and needs to sort upon them).
However, as development was done a single mongod, we've encountered this error only now when deploying at scale. Now this requires changing our application code accordingly.
One of the reasons we chose MongoDB was the "scale without affecting existing data or application code" paradigm. Therefore I believe the same behavior of mongos' must be enforced on the shards as well to allow that.
Thanks
Shay



 Comments   
Comment by Shay Asher [ 14/Oct/13 ]

Thanks.

Comment by Eliot Horowitz (Inactive) [ 14/Oct/13 ]

Yes, this should be handled automatically, such that the query works in both (not neither. There is an older ticket SERVER-10831 that we'll use to track.

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