[DOCS-5598] Document passing array to $orderby/.sort() Created: 11/Jun/15  Updated: 11/Jan/17  Resolved: 16/Jun/15

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Improvement Priority: Minor - P4
Reporter: Kevin Pulo Assignee: Kay Kim (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-18905 Server should reject array values for... Closed
Participants:
Days since reply: 8 years, 35 weeks, 1 day ago

 Description   

Apparently, $orderby (and therefore cursor.sort()) accept an array (as well as the more usual object-based sort specification):

> db.foo.find().sort("")
error: {
        "$err" : "Can't canonicalize query: BadValue sort must be object or array",
        "code" : 17287
}
> db.foo.find().sort([])
{ "_id" : ObjectId("54ffd9def90b9eca96351c11") }
{ "_id" : ObjectId("554acc2f0141860a26d4784d") }
{ "_id" : ObjectId("554c3d70c96e4d4352323672") }
{ "_id" : ObjectId("554c3da5c96e4d4352323673") }
{ "_id" : ObjectId("554c3db2c96e4d4352323674") }

However, the documentation pages for $orderby and cursor.sort() only mention the traditional object notation, eg. db.foo.find().sort( { _id: 1 } ).

It would be good if the docs could explain that the array notation is possible, and how to use it (i.e. what should be inside the array, and how it's interpreted).



 Comments   
Comment by J Rassi [ 16/Jun/15 ]

I do not believe that we should endorse use of this feature, as it has been broken in many released versions of the server and will be removed in the near future (see my comment in SERVER-18905 for details). As as result, I would not recommend describing it in the documentation.

Generated at Thu Feb 08 07:50:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.