我正在尝试使用我帖子中的用户名获取所有最新评论。我尝试使用以下方式获取最新记录:
"$sort": {
"rd_comments.created_at": -1
}
以下是完整的查询:
[ {
"$lookup": {
"from": "userlist",
"localField": "u_id",
"foreignField": "u_id",
"as": "userlist"
} }, {
"$unwind": "$userlist" }, {
"$match": {
"status": {
"$ne": 2
}
} }, {
"$skip": 0 }, {
"$limit": 10 }, {
"$sort": {
"rd_comments.created_at": -1
} }, {
"$project": {
"username": "$userlist.username",
"_id": 1,
"comment": 1,
"created_at": 1
} } ]
它给了我未分类的结果。
[增订]
用户文档:
u_id | username
--------------------------
1 | Shail
--------------------------
2 | Mukky
--------------------------
评论文件:
c_id | u_id | comments | created_at
--------------------------------------------------------
1 | 1 | Nice Post3 | NumberInt(1483405261)
--------------------------------------------------------
2 | 2 | Nice Post3 | NumberInt(1483318861)
--------------------------------------------------------
3 | 2 | Nice Post2 | NumberInt(1488522534)
--------------------------------------------------------
4 | 2 | Nice Post1 | NumberInt(1488522033)
--------------------------------------------------------
5 | 1 | Nice Post2 | NumberInt(1488521530)
--------------------------------------------------------