[SERVER-27492] Support $natural sorts on views Created: 21/Dec/16 Updated: 06/Dec/22 Resolved: 03/Jan/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework, Querying |
| Affects Version/s: | 3.4.0 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Nathan Fan [X] | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | read-only-views | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Server 3.4.0 |
||
| Issue Links: |
|
||||||||||||
| Assigned Teams: |
Query
|
||||||||||||
| Participants: | |||||||||||||
| Description |
|
In the code I tried to treat Views the same as collections. We applied .sort({$natural:1}) to all the queries. For normal collections the driver worked as before, but the sort failed on Views retrieval. The example shown below:
This returned:
Is it the way I dealt with views wrongly? P.S. mongoclient / command line (mongo) having the same problem as Java driver:
Thanks for helping guys. |
| Comments |
| Comment by Charlie Swanson [ 03/Jan/17 ] | |||||||||||||||||||||||||||||
|
After review by the Query team, we have decided that $natural is more of a hint specification than a sort specification, and doesn't make sense in the middle of a pipeline. Allowing a $natural sort against a view may require adding that $sort after a $group stage or some other stage which does not preserve the order of documents. A $natural sort specification means to order the results in the order of a collection scan, which cannot be easily recreated at that point. Adding hint support to the aggregation pipeline is tracked via | |||||||||||||||||||||||||||||
| Comment by Nathan Fan [X] [ 21/Dec/16 ] | |||||||||||||||||||||||||||||
|
Thanks for the clarification | |||||||||||||||||||||||||||||
| Comment by Kyle Suarez [ 21/Dec/16 ] | |||||||||||||||||||||||||||||
|
Hi NathanFan, it's true that $natural sorts do not work with views. This is because all views are implemented as aggregation pipelines, and the aggregation system does not support $natural sorts. I've converted this ticket into a feature request to support these sorts on views and sent it to the query team for consideration. Please continue to watch this ticket for updates.
You can either query the system.views collection, or check the output of the listCollections command, which gives output similar to this:
Regards, | |||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 21/Dec/16 ] | |||||||||||||||||||||||||||||
|
Hi Nathan, Since this issue is not specific to the Java driver, I took the liberty of moving it to the Core Server project. |