我需要在数组中填充...
messageModel.aggregate([
{"$match": {$and: [
{$or: [{"to": system.mongoose.Types.ObjectId(userId)}, {"from": system.mongoose.Types.ObjectId(userId)}]}
]
}
},
{
"$group": {
"_id": "$conversationId",
"conversation": {"$push": {'from': "$from"}}
}
},
{"$lookup": {
"from": "user",
"localField": "conversation.from",
"foreignField": "_id",
"as": "to"
}},
{"$unwind": {"path": "$conversation.from"}},
{"$project": {
"conversation.from.firstName": "$conversation.from.firstName"
}
}
]
这个返回空数组有什么问题?如果我不使用数组,那么它可以工作,如果只是采用第一个元素......任何解决方案?