Database
[{"title":"test1",sort:1,parent:1},{"title":"test2",sort:7,parent:1},{"title":"test3",sort:5,parent:1},{"title":"test4",sort:1,parent:2},{"title":"test5",sort:7,parent:2},{"title":"test6",sort:5,parent:2}]
Query
db.collection.aggregate([{/** sort parents and then the children*/$sort:{"parent":1,"sort":1}},{$group:{_id:"$parent",docs:{/** docs will be already sorted in this array*/$push:"$$ROOT"}}},{/** set each doc `sort` field to the value it should be* based on its index in docs*/$set:{docs:{$map:{input:"$docs",in:{"_id":"$$this._id","sort":{$add:[1,{$multiply:[{$indexOfArray:["$docs","$$this"]},10]}]}}}}}},{$unwind:"$docs"},{$replaceRoot:{newRoot:"$docs"}},{$merge:"collection"}])