0
ich Abfrage etwas wie dieses:
{"$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": 1}
}
},
Ich brauche keine Haupt-$match
zu bearbeiten Ich brauche nur Summe von unreaded
Nachrichten zu erhalten,
ich so etwas wie dieses brauchen : "unreaded": {"$sum": 1, {$match: {unreaded: true}}}
Irgendeine Lösung für dieses?
Wie kann ich auch eine andere cond es? Ich muss auch "$ to" gleich sein "system.mongoose.Types.ObjectId (userId)" Benötigen Sie etwas wie folgt: '" nicht definiert ": {" $ sum ": {$ cond: {if:" $ unloaded " && ("$ to" == system.mongoose.Types.ObjectId (userId)), dann: 1, sonst: 0}}}? – Vladimir