我有这样的查询:
{"$match": {$or: [{"to": system.mongoose.Types.ObjectId(userId)}, {"from": system.mongoose.Types.ObjectId(userId)}]}},
{"$sort": {"createDate": -1}},
{
"$group": {
"_id": "$conversationId",
"from": {"$first": "$from"},
"to": {"$first": "$to"},
"content": {"$first": "$content"},
"createDate": {"$first": "$createDate"},
"unreaded": {"$sum": {"$cond":
{if :
{
$and: [
{
"$eq": [
"$unreaded", 1
]
},
{
"$eq": ["$to", system.mongoose.Types.ObjectId(userId)]
}
]
}, then: 1, else: 0}}}
unreaded
会为每个会话返回未审核的邮件,如何获取所有unreaded
条消息的总和?