[SERVER-1601] Sort parameter excludes any overlapping fields passed to find Created: 09/Aug/10  Updated: 12/Jul/16  Resolved: 10/Aug/10

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 1.6.0
Fix Version/s: 1.7.0

Type: Bug Priority: Major - P3
Reporter: Van Nguyen (vnguyen) Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

CentOS, OSX


Operating System: Linux
Participants:

 Description   

Ok, so we've found something that looks like it caused a lot of our production code to break.

We are running a nightly build (to fix the getMore issue) of 1.6.x. We have replica sets running with 3 replicas which act as a single shard. Only one shard is running, all others are not yet enabled. We have a users collection where documents have two main keys or paths:

1) "key" which is a string
2) "account" which is an object

We're running the following query* and an example result follows:

> db.users.find({},

{"key":1, "account":1}

).skip(0).limit(50).sort(

{"account.created_at":-1}

);
{ "_id" : ObjectId("4c6062392b855c70fe65963b"), "account" :

{ "created_at" : 1281385017984 }

, "key" : "xxxxxxxx" }

  • please ignore the fact we don't have to use a separate created_at

Account has many other subkeys that are not visible in the result of the find.

Results of the explain query:
> db.users.find({},

{"key":1, "account":1}

).skip(0).limit(50).sort(

{"account.created_at":-1}

).explain()
{
"clusteredType" : "ParallelSort",
"shards" : {
"chronotrigger/crono:10000,crono:10001,lucca:30000" : [
{
"cursor" : "BtreeCursor account.created_at_1 reverse",
"nscanned" : 194,
"nscannedObjects" : 194,
"n" : 193,
"millis" : 0,
"indexBounds" : {
"account.created_at" : [
[

{ "$maxElement" : 1 }

,

{ "$minElement" : 1 }

]
]
}
}
]
},
"nscanned" : 194,
"nscannedObjects" : 194,
"n" : 193,
"millisTotal" : 0,
"millisAvg" : 0,
"numQueries" : 1,
"numShards" : 1
}

Interesting side case #1:

> db.users.find({},

{"key":1, "account.username":1}

).skip(0).limit(50).sort(

{"account.created_at":1}

);
{ "_id" : ObjectId("4c5bbfb5f75364df46b5da1b"), "account" :

{ "created_at" : 1276113472661, "username" : "xxxxxx" }

, "key" : "xxxxxx" }

Interesting side case #2:
> db.users.find({},

{"key":1, "account":1}

).skip(0).limit(50).sort({$natural:1});

    • this returns what we were basically expecting but its sorted by _id time vs created_at time (which may actually differ in most rows)

Please let me know if additional information is needed. Thanks for your time.



 Comments   
Comment by Mathias Stearn [ 10/Aug/10 ]

This should be solved if you build from master now. If not, please reopen.

Comment by auto [ 10/Aug/10 ]

Author:

{'login': 'RedBeard0531', 'name': 'Mathias Stearn', 'email': 'mathias@10gen.com'}

Message: better adding of sort key to projection in mongos SERVER-1601
http://github.com/mongodb/mongo/commit/b2569f1650e5486ab201bf13ba086d86820a8f3c

Generated at Thu Feb 08 02:57:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.