下面是我的模式..我需要得到my'file_id'(我將定義我的file_id)與不同的'user_email'計數..注意..不計數file_id與類似和不同的user_email我只需要計數我的file_id與不同的user_email.any幫助?如何查找和分組不同的值並在mongoDb中計數?
{
"_id" : ObjectId("591bedc8c942a3514ed09b24"),
"file_id" : "58450c20b053dc426b935927",
"description" : "get your output ready",
"user_email" : "[email protected]",
"__v" : 0
}
{
"_id" : ObjectId("591bedc8c942a3514ed09b25"),
"description" : "get your output ready",
"user_email" : "[email protected]",
"__v" : 0
}
{
"_id" : ObjectId("591bedc8c942a3514ed09b26"),
"file_id" : "58450c20b053dc426b935927",
"description" : "get your output ready",
"user_email" : "[email protected]",
"__v" : 0
}
{
"_id" : ObjectId("591bedc8c942a3514ed09b27"),
"file_id" : "58450c20b053dc426b935927",
"description" : "get your output ready",
"user_email" : "[email protected]",
"__v" : 0
}
{
"_id" : ObjectId("591beea4a62559b4506549e0"),
"file_id" : "58450c20b053dc426b935927",
"description" : "get your output ready",
"user_email" : "[email protected]",
"__v" : 0
}
db.myschema.aggregate({$group:{"file_id":"58450c20b053dc426b935927","user_email" : "[email protected]",count: { $sum: 1 }} })
你的問題不清楚 – Lekhnath
我需要得到的文件id的數量,我用我的查詢與不同的用戶電子郵件定義..如果有10個記錄具有相同的file_id和相同的user_email我需要計數爲1而不是10. – Jagadeesh