Database

db={"posts":[{"_id":"p1","comments":[{"likes":[{createdBy:{username:"testusername",_id:"u1"}},{createdBy:{username:"testusername2",_id:"u2"}}],"content":"test comment"},{"likes":[{createdBy:{username:"testusername",_id:"u1"}}],"content":"another test comment"}]}]}

Query

db.posts.aggregate([{"$match":{"_id":"p1"}},{"$project":{"comments":{"$slice":["$comments",-5]}}},{"$project":{likes:{"$map":{"input":"$comments","as":"c","in":{content:"$$c.content",likedByU1:{"$map":{"input":"$$c.likes","as":"l","in":{$eq:["$$l.createdBy._id","u1"]}}}}}}}},{"$project":{likes:{"$map":{"input":"$likes","as":"l","in":{content:"$$l.content",likedByU1:{"$anyElementTrue":["$$l.likedByU1"]}}}}}}])

Result