Database

[{_id:1,name:"John",lastName:"Doe",accounts:[{provider:"google",email:"my@email.com",password:"p4ssw0rd"}]},{_id:2,accounts:[{provider:"simple",email:"my2@email.com",password:"p4ssw0rd2"}]}]

Query

db.collection.aggregate([{$match:{_id:{$in:[1,2]}}},{$unwind:"$accounts"},{$group:{_id:"joined",name:{$first:"$name"},lastName:{$first:"$lastName"},accounts:{$push:"$accounts"}}}])

Result