If you want to leave these time elements, you can use the aggregate command from mongo 2.2+ to extract the minimum and maximum time elements, undo all the time elements and press the minutes and maximum versions (with some changes, it could do your job):
smax=db.collection.aggregate([{$unwind: "$time"}, {$project: {tstamp:"$time.stamp",treason:"$time.reason"}}, {$group: {_id:"$_id",max:{$max: "$tstamp"}}}, {$sort: {max:1}}]) smin=db.collection.aggregate([{$unwind: "$time"}, {$project: {tstamp:"$time.stamp",treason:"$time.reason"}}, {$group: {_id:"$_id",min:{$min: "$tstamp"}}}, {$sort: {min:1}}]) db.students.update({},{$unset: {"scores": 1}},false,true) smax.result.forEach(function(o) {db.collection.update({_id:o._id},{$push: {"time": {stamp: o.max ,reason: "new"}}},false,true)}) smin.result.forEach(function(o) {db.collection.update({_id:o._id},{$push: {"time": {stamp: o.min ,reason: "update"}}},false,true)})
source share