[SERVER-5672] Natural Sort ignores Index Created: 20/Apr/12 Updated: 05/Jan/14 Resolved: 20/Apr/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance |
| Affects Version/s: | 2.0.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Diego Maxi | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Capped Collection / 'rf' is sparse-indexed |
||
| Issue Links: |
|
||||||||
| Operating System: | Linux | ||||||||
| Participants: | |||||||||
| Description |
|
db.log.find( { rf : 'o-5556457634'}).sort( { '$natural' : -1 }).explain(); Without the 'natural' sort: db.log.find( { rf : 'o-5556457634'}).explain(); |
| Comments |
| Comment by Diego Maxi [ 24/Apr/12 ] |
|
MongoDB seems to be a perfect solution to store large sets of application logs; and occasionally, I need to retrieve some of them (could be based on user_ip, user_id, log_type, etc). On those cases I need the resulting list to be sorted in reverse chronological order. Will give it a shot on the user group. Thanks! |
| Comment by Eliot Horowitz (Inactive) [ 24/Apr/12 ] |
|
What are you trying to do exactly? |
| Comment by Eliot Horowitz (Inactive) [ 24/Apr/12 ] |
|
What are you trying to do exactly? |
| Comment by Diego Maxi [ 23/Apr/12 ] |
|
What about reverse natural sort on a query like this? |
| Comment by Eliot Horowitz (Inactive) [ 21/Apr/12 ] |
|
db.log.find( { rf : 'o-5556457634'}).sort ( { rf : -1 }) |
| Comment by Diego Maxi [ 21/Apr/12 ] |
|
The problem is that I need the results in reverse disk order. Do I have any way to accomplish this without creating additional fields? thanks! |
| Comment by Eliot Horowitz (Inactive) [ 21/Apr/12 ] |
|
When you sort via an index, if the keys are dups, then the sort is disk order. So you don't need to do anything special. |
| Comment by Diego Maxi [ 21/Apr/12 ] |
|
So the only way to accomplish this is by creating and indexing an additional custom field just for this task? Haven's seen any mention about this logic in the documentation and I thought the engine was able to look at the order on disk after getting the results (assuming the 'find' results will carry the disk order internally). Thanks. |
| Comment by Eliot Horowitz (Inactive) [ 20/Apr/12 ] |
|
That's what $natural is supposed to do. |