我使用$ lookup进行左连接,但我无法按帖子中的created_at字段对结果进行排序
我的查询
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 });
}
})
现在我想按created_at字段
按降序对posts数组进行排序