[DOCS-1898] Using $push with a $sort also requires $slice Created: 09/Sep/13  Updated: 11/Jan/17  Resolved: 25/Sep/13

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

Type: Task Priority: Major - P3
Reporter: Stennie Steneker (Inactive) Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 10 years, 21 weeks ago

 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 :



 Comments   
Comment by auto [ 25/Sep/13 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-1898 sort requires slice as well as each
Branch: master
https://github.com/mongodb/docs/commit/4095e09e1501ccf4c6d409768240f0f42b7bdcff

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