[SERVER-8069] Support full $slice / $sort semantics in $push Created: 03/Jan/13  Updated: 07/Mar/14  Resolved: 01/Oct/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: None
Fix Version/s: 2.5.3

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

Issue Links:
Depends
depends on SERVER-6399 Refactor update() code Closed
Duplicate
is duplicated by SERVER-8746 $push w/ $sort: make $slice optional Closed
Related
related to DOCS-2078 Support full $slice / $sort semantics... Closed
related to SERVER-8746 $push w/ $sort: make $slice optional Closed
is related to SERVER-991 $push with $slice + $sort Closed
is related to SERVER-10988 Support $slice from middle for $push Closed
is related to SERVER-9590 Update $push + $sort should be able t... Closed
Participants:

 Description   

SERVER-8008 and SERVER-991 introduce the clause $slice to the $push update mod. The clause now only supports negative slices (trimming from the back of the array). The full $slice semantics support trimming from the front and also skipping (moved to issue SERVER10988). We'd like to support all these features here.

In terms of $sort, we'd like to use query semantics for that clause. For example,

doc = { x: [ {a: [{b:1},{b:3}], a: [{b:2},{b:0}] } ] }
 
$sort: {'a.b':1} would reorder the two 'a' elements.  

This allows slicing from the front or back of the array:

> db.a.save({_id:1, a: [1,2,3]})
 
// Top slice
> db.a.update({}, {$push: {a: {$each : [4], $slice: 2}}})
> db.a.find()
{_id:1, a:[1,2]}
 
// Bottom slice
> db.a.update({}, {$push: {a: {$each : [4], $slice: -2}}})
> db.a.find()
{_id:1, a:[2,4]}



 Comments   
Comment by auto [ 01/Oct/13 ]

Author:

{u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-9590 SERVER-8069: make sure to validate $sort number for $push and remove old invalid tests
Branch: master
https://github.com/mongodb/mongo/commit/8bcb0be94d3f1add3fc11e859be1f87c1e507e46

Comment by auto [ 01/Oct/13 ]

Author:

{u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-9590 SERVER-8069: $push with $slice and/or $sort, and element sorting
Branch: master
https://github.com/mongodb/mongo/commit/fff69fa431248586ee4ccfdb0c43960040421558

Comment by Scott Hernandez (Inactive) [ 14/Aug/13 ]

$slice/$sort could be supported without $push, but that doesn't fit our modifier model well. Logically it makes sense that you might just want to change the size or sort without adding anything. This can be accomplished with $each:[] in the current syntax.

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