[SERVER-9077] How to optimize the query Created: 22/Mar/13 Updated: 10/Dec/14 Resolved: 25/Mar/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | Arati Sethy | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Linux |
||
| Participants: |
| Description |
|
I have a capped collection with 1.3 million documents indexed on id.
Thanks |
| Comments |
| Comment by Andre de Frere [ 25/Mar/13 ] | |
|
Hi Arati, Because you only have an index on _id the entire collection is being scanned when you are querying for { port : 2 }- every document has to be checked for the key { port : 2 }. The explain output is indicating that the _id index is being used to sort the results, but the entire result set has to be brought back as there is no index on port. If you ensure an index on port, your query will return a lot more quickly. You could do this with:
A couple of other points.
| |
| Comment by Arati Sethy [ 25/Mar/13 ] | |
|
Query is ).skip(0).limit(20).sort( {"_id": -1}).explain(). | |
| Comment by Aaron Staple [ 22/Mar/13 ] | |
|
Hi Arati - Can you send the full query? |