[DOCS-7183] Comment on: "manual/reference/method.txt" Created: 17/Feb/16 Updated: 03/Nov/17 Resolved: 04/Oct/16 |
|
| Status: | Closed |
| Project: | Documentation |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 01112017-cleanup |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Docs Collector User (Inactive) | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | collector-298ba4e7 | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Ubuntu, MongoDB 3.0.9 version , Using RoboMongo Location: https://docs.mongodb.org/manual/reference/method/ |
||
| Participants: | |
| Days since reply: | 7 years, 51 weeks, 6 days ago |
| Description |
|
I have a collection such as:- { "_id" : ObjectId("56c2a7320efba7c30cdb139b"), "country_code" : "US", "country_name" : "United States", "region_name" : "Hawaii", "city_name" : "'Aiea", "time_zone" : "-10:00\"\r" }Am doing, db.collection.distinct("countries_name") to get the distinct country_names. Now i want to sort them , but sort is not applicable on distinct. ) is not a function (shell):1 |
| Comments |
| Comment by Ravind Kumar (Inactive) [ 18/Feb/16 ] | |
|
Draft reply: Hello Ratnadeep, The distinct command does not accept a sort parameter, nor does the shell's distinct() helper allow modifiers like .sort() to be chained. However, since distinct() returns an array, once you get the results of distinct(), you could use JavaScript array's sort() method to sort the results on the client side. For example,
|