Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-5598

Document passing array to $orderby/.sort()

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • 01112017-cleanup
    • None
    • manual
    • None

    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).

      Attachments

        Activity

          People

            kay.kim@mongodb.com Kay Kim (Inactive)
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              8 years, 35 weeks, 1 day ago