db.test_update.insert({name: "2.4"})
db.test_update.update({name :"2.4"}, { $push: { n: { $each: [{x:10},{x:4}, {x:1}] , $slice: -1 , $sort: { x:1 }}}})
db.test_update.findOne()
{
"_id" : ObjectId("51c8a7f31c7a4e0a10e4f14a"),
"n" : [
{
"x" : 10
}
],
"name" : "2.4"
}
db.test_update.update({name:"2.4"},{ $set : { n : [] }})
db.test_update.update({name :"2.4"}, { $push: { n: { $slice : -1, $each: [{x:10},{x:4}, {x:1}] , $sort: { x:1 }}}})
db.test_update.findOne()
{
"_id" : ObjectId("51c8a7f31c7a4e0a10e4f14a"),
"n" : [
{
"$slice" : -1,
"$each" : [
{
"x" : 10
},
{
"x" : 4
},
{
"x" : 1
}
],
"$sort" : {
"x" : 1
}
}
],
"name" : "2.4"
}