[JAVA-490] Check value type that passed to a sort method Created: 14/Dec/11 Updated: 25/Jun/13 Resolved: 25/Jun/13 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Uladzimir Mihura | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Please, take a look at the following code. I think that only int -1 or 1 should be allowed here.
|
| Comments |
| Comment by Jeffrey Yemin [ 25/Jun/13 ] | |||||||
|
We can use helpers to guide users in the right direction. | |||||||
| Comment by Scott Hernandez (Inactive) [ 29/Dec/11 ] | |||||||
|
Vova, are these docs not sufficient? http://www.mongodb.org/display/DOCS/Indexes | |||||||
| Comment by Uladzimir Mihura [ 29/Dec/11 ] | |||||||
|
Hi Scott, Can you please clarify? I haven't found any other information about that. -vova | |||||||
| Comment by Scott Hernandez (Inactive) [ 29/Dec/11 ] | |||||||
|
The server is in charge of validating... there are many more types of indexes than just ascending/descending. | |||||||
| Comment by Uladzimir Mihura [ 29/Dec/11 ] | |||||||
|
Similar situation when adding indexes. In documentation:
But in code:
| |||||||
| Comment by Brendan W. McAdams [ 14/Dec/11 ] | |||||||
|
We should restrict the use of anything but int. This is likely an issue that will require generics to filter what is passed in the DBObject argument however. | |||||||
| Comment by Brendan W. McAdams [ 14/Dec/11 ] | |||||||
|
Technically, any positive value is "Ascending sort" and any negative value is "descending sort". That's the server-side behavior. | |||||||
| Comment by Alex Litvinok [ 14/Dec/11 ] | |||||||
|
In PHP works like Java. If the direction not equal -1, it will be used as 1. | |||||||
| Comment by Vitali Ausianik [ 14/Dec/11 ] | |||||||
|
In Python it works fine. Function Cursor.sort() takes either a single key and a direction, or a list of (key, direction) pairs. The key(s) must be an instance of (str, unicode), and the direction(s) must be one of (1,-1). If direction not in (1, -1) - exception will be generated. |