如何在mongodb中选择。
Select room(distinct), count(where read =1)
from chat
where from = "1" or to ="1"
这是我的json
{
"_id" : ObjectId("595da6052008fc2213db32f6"),
"room" : "1_40",
"from" : "1",
"to" : "40",
"user_name" : "Tran Cot",
"mes" : "hgfd",
"time" : 1499309573832,
"read" : 1
}
答案 0 :(得分:0)
如果您想要每个房间的总阅读信息..
db.chat.aggregate([
{ $match: { $or: [{ from: "41" }, { to: "41" }] } },
{ $group: {
_id: "$room",
count: {
$sum: {
$cond: { if: $eq: ["$read", false], then: 1, else: 0 }
}
}
}}
]);