[SERVER-4135] Sort using compound indexing Created: 24/Oct/11  Updated: 29/Feb/12  Resolved: 25/Oct/11

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

Type: Question Priority: Major - P3
Reporter: Wei Kong Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

if I create a compound index

parent_id + name

when I do a query and sort by name, does it use index to do the sort? How can I make sure that sort by name will use index if I only have a compound index?



 Comments   
Comment by Eliot Horowitz (Inactive) [ 25/Oct/11 ]

yes, if you have an index on parent_id , name a query like find (

{ parent_id : ... }

).sort(

{ name : 1 }

)
will use an index

please try explain()

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