Database

db={user:[{"_id":"5ecee2189fdd1b0004056936","name":"Mike",}],history:[{"_id":"5ecb263c166b8500047c1411","userId":"5ecee2189fdd1b0004056936","what":"Log IN"},{"_id":"5ecb263c166b8500047c1422","userId":"5ecee2189fdd1b0004056999","what":"Log IN"},{"_id":"5ecb263c166b8500047c1433","userId":"5ecee2189fdd1b0004056936","what":"Log OUT"},{"_id":"5ecb263c166b8500047c1444","userId":"5ecee2189fdd1b0004056999","what":"Log OUT"}]}

Query

db.user.aggregate([{$lookup:{from:"history",localField:"_id",foreignField:"userId",as:"history"}},{$project:{name:1,history:{$map:{input:"$history",as:"h",in:{_id:"$$h._id",what:"$$h.what"}}}}}])

Result