I have used $ lookup to make left join but I am not able to sort the result by created_at field in posts
My query
pipeline = [{$match: { "_id" : mongoose.Types.ObjectId(req.body.celebrity_id)}},
{$lookup : { from : "posts" , localField : "_id" ,foreignField : "celebrity_id", as : "posts"}},
]`
User.aggregate( pipeline )
.exec(function(err , user){
console.log(user)
if(err){
res.json({'success' : false , msg : 'Something went wrong please try again'});
}else{
res.json({'success' : true , msg : 'success' , 'data' : user });
}
})
Now I want to sort the posts array in descending order by created_at field