Database
[{name:"mehdi",grades:[{a:1,b:[2,3,4],c:3,d:4,e:5},{a:11,b:[22,33,44],c:33,d:44,e:55}]}]
Query
db.collection.aggregate([{$project:{grades:{$map:{input:"$grades",in:{a:{$cond:[{$eq:[{$type:"$$this.a"},"array"]},{$arrayElemAt:["$$this.a",0]},"$$this.a"]},b:{$cond:[{$eq:[{$type:"$$this.b"},"array"]},{$arrayElemAt:["$$this.b",0]},"$$this.b"]},}}}}}])