Created
January 27, 2012 23:31
-
-
Save tanordheim/1691573 to your computer and use it in GitHub Desktop.
MongoDB multiple sort fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > db.users.ensureIndex({instance_id: 1, first_name: 1, last_name: 1}); | |
| > db.users.find({ instance_id: ObjectId("4f22b9cf7e298452c5000001") }).sort({first_name: 1, last_name: 1}).explain() | |
| { | |
| "cursor" : "BtreeCursor instance_id_1_first_name_1_last_name_1", | |
| "nscanned" : 2, | |
| "nscannedObjects" : 2, | |
| "n" : 2, | |
| "millis" : 0, | |
| "nYields" : 0, | |
| "nChunkSkips" : 0, | |
| "isMultiKey" : false, | |
| "indexOnly" : false, | |
| "indexBounds" : { | |
| "instance_id" : [ | |
| [ | |
| ObjectId("4f22b9cf7e298452c5000001"), | |
| ObjectId("4f22b9cf7e298452c5000001") | |
| ] | |
| ], | |
| "first_name" : [ | |
| [ | |
| { | |
| "$minElement" : 1 | |
| }, | |
| { | |
| "$maxElement" : 1 | |
| } | |
| ] | |
| ], | |
| "last_name" : [ | |
| [ | |
| { | |
| "$minElement" : 1 | |
| }, | |
| { | |
| "$maxElement" : 1 | |
| } | |
| ] | |
| ] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment