Ik heb de duplicaten opgelost met $group en $first
db.getCollection('user').aggregate([
{$lookup: {from: "post", localField: "_id", foreignField: "userId", as: "post"}},
{$unwind: { path: "$post", preserveNullAndEmptyArrays: true }},
{$sort: {"post.createdAt": -1}},
{$group: {"_id": "$_id", "name": {$first: "$name"}, "post": {$first: "$post"}},
{$project: {"_id": 1, "name": 1, "post": 1}}
])
Voel je vrij om je antwoord te posten