Database

db={"profiles":[{"_id":ObjectId("5e2c98fc3d785252ce5b5693"),"imageUrl":"https://i.pravatar.cc/300","firstname":"Jakos","surname":"Lemi","email":"lemi@email.com","bio":"My bio bio","title":"Senior IT developer","area":"Copenhagen","username":"Jakos","experience":[{"image":"https://via.placeholder.com/150","_id":ObjectId("5e3975f95fbeec9095ff3d2f"),"role":"Developer","company":"Google","startDate":ISODate("2018-11-09T23:00:00.000Z"),"endDate":ISODate("2019-01-05T23:00:00.000Z"),"area":"Copenhagen","createdAt":ISODate("2020-02-04T13:47:37.167Z"),"updatedAt":ISODate("2020-02-04T13:47:37.167Z")},{"image":"https://via.placeholder.com/150","_id":ObjectId("5e3978bf5e399698e20c56d4"),"role":"Developer","company":"IBM","startDate":ISODate("2018-11-09T23:00:00.000Z"),"endDate":ISODate("2019-01-05T23:00:00.000Z"),"area":"Copenhagen","createdAt":ISODate("2020-02-04T13:59:27.412Z"),"updatedAt":ISODate("2020-02-04T13:59:27.412Z")}],"createdAt":ISODate("2020-01-25T19:37:32.727Z"),"updatedAt":ISODate("2020-02-04T23:14:37.122Z"),"__v":NumberInt("0")}],"posts":[{"_id":ObjectId("5e3beb639e072afedd19dcef"),"username":ObjectId("5e2c98fc3d785252ce5b5693"),"image":"https://via.placeholder.com/150","text":"My awesome post","createdAt":ISODate("2020-02-06T10:33:07.22Z"),"updatedAt":ISODate("2020-02-06T10:33:07.22Z"),"reactions":[],"__v":NumberInt("0")}]}

Query

db.profiles.aggregate([{$match:{username:"Jakos"}},{$lookup:{from:"posts",localField:"_id",foreignField:"username",as:"posts"}},{$project:{username:1,posts:1,postsCount:{$size:"$posts"},_id:0}}])

Result