[SERVER-8715] $push with only $sort pushes a $sort field Created: 25/Feb/13  Updated: 11/Jul/16  Resolved: 02/Oct/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.4.0-rc0
Fix Version/s: 2.5.3

Type: Improvement Priority: Major - P3
Reporter: Kristina Chodorow (Inactive) Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to DOCS-2078 Support full $slice / $sort semantics... Closed
Participants:

 Description   

It seems like this should error out. Example:

> db.set.update({}, {$push : {a : {$each : [{"title" : "x", "rating" : 6}, {title:"y", "rating" : 3}, {title:"z", rating:10}]}}}, true)
> db.set.update({}, {"$push" : {"a" : {"$sort" : {"a.rating" : 1}}}})
> db.set.find().pretty()
{
        "_id" : ObjectId("512b8e6dae74c67969e404cc"),
        "a" : [
                {
                        "title" : "x",
                        "rating" : 6
                },
                {
                        "title" : "y",
                        "rating" : 3
                },
                {
                        "title" : "z",
                        "rating" : 10
                },
                {
                        "$sort" : {
                                "a.rating" : 1
                        }
                }
        ]
}



 Comments   
Comment by Scott Hernandez (Inactive) [ 02/Oct/13 ]

> db.set.save({_id:1, a:[]})
> db.set.update({}, {"$push" : {"a" : {"$sort" : {"a.rating" : 1}}}})
cannot use '$' as values
> db.set.find()
{ "_id" : 1, "a" : [ ] }

--Better error messages to come...

Comment by Kristina Chodorow (Inactive) [ 25/Feb/13 ]

Same deal with just $slice and $sort:

test> db.set.update({}, {$push : {a : {$slice:-2, $sort:{"a.rating":1}}}})
test> db.set.find().pretty()
{
        "_id" : ObjectId("512b8e6dae74c67969e404cc"),
        "a" : [
                {
                        "title" : "x",
                        "rating" : 6
                },
                {
                        "title" : "y",
                        "rating" : 3
                },
                {
                        "title" : "z",
                        "rating" : 10
                },
                {
                        "$slice" : -2,
                        "$sort" : {
                                "a.rating" : 1
                        }
                }
        ]
}

Generated at Thu Feb 08 03:18:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.