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

Using $push with a $sort also requires $slice

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 01112017-cleanup
    • mongodb-2.4
    • manual
    • None

    Description

      In MongoDB 2.4 (tested with 2.4.6) you cannot push to a sorted array without also specifying a $slice.

      eg. modifying the example from http://docs.mongodb.org/manual/reference/operator/push/:

      db.students.update( { name: "joe" },
                          { $push: { quizzes: { $each: [ { id: 3, score: 8 },
                                                         { id: 4, score: 7 },
                                                         { id: 5, score: 6 } ],
                                                $sort: { score: 1 }
                                              }
                                   }
                          }
                        )

      Returns the error:

      cannot have a $sort without a $slice

      I think this caveat should be mentioned on :

      Attachments

        Activity

          People

            kay.kim@mongodb.com Kay Kim (Inactive)
            stephen.steneker@mongodb.com Stennie Steneker (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 21 weeks ago