Database
[{"_id":"abc","field1":[],/** array of subdocuments, may be empty*/"field2":"somVal","field3":[/** array of subdocuments, may be empty*/{"fieldToSort":"bcdef"},{"fieldToSort":"abcde"}]},{"_id":"def","field1":[/** array of subdocuments, may be empty*/{"fieldToSort":"bcdef"},{"fieldToSort":"abcde"}],"field3":[]/** array of subdocuments, may be empty* field2 is missing*/}]
Query
db.collection.aggregate([{"$addFields":{newArr:{"$objectToArray":"$$ROOT"}}},{"$addFields":{newArr:{"$filter":{"input":"$newArr","cond":{$in:["$$this.k",["field1","field3"]]}}},root:"$$ROOT"}},{"$unwind":"$newArr"},{"$unwind":"$newArr.v"},{"$sort":{"newArr.v.fieldToSort":1}},{"$group":{"_id":{_id:"$_id",field:"$newArr.k"},"data":{"$push":"$newArr.v"},root:{$first:"$root"}}},{"$group":{"_id":"$_id._id","data":{"$push":{k:"$_id.field",v:"$data"}},root:{$first:"$root"}}},{$project:{data:{"$arrayToObject":"$data"},root:1}},{"$replaceRoot":{"newRoot":{"$mergeObjects":["$root","$data"]}}},{$project:{newArr:0}}])