-3
我想通過mongodb中的特定字段來總結upvotes的數量。 例如返回約翰得到的upvotes數量的總和。我將如何總結由mongodb中的特定字段的upvotes的數量
{
"_id": "fc0996a9726e4bf08c3d614afe05c7a8",
"blog_id": "f8da5ae532aa44f6a54d86fd822f7d52",
"author": "John",
"content": "Hello",
"upvotes": 3,
}
{
"_id": "dea0a9713a734717920b652eed268b99",
"blog_id": "f8da5ae532aa44f6a54d86fd822f7d52",
"author": "John",
"content": "Hello",
"upvotes": 2,
}
{
"_id": "3d286c4ce54046f4aac9ea627a48f04e",
"blog_id": "f8da5ae532aa44f6a54d86fd822f7d52",
"author": "John",
"content": "Hello",
"upvotes": 1,
}
{
"_id": "6782b555dd8c47f58dba28e60fda4a5f",
"blog_id": "f8da5ae532aa44f6a54d86fd822f7d52",
"author": "123",
"content": "Bye",
"upvotes": 2,
}
我該如何總結upvotes並返回一個值6,upvotes只有John已經得到。 此外,我使用Python的Web應用程序,用燒瓶。
謝謝
使用骨料與$匹配和$和運營商。 https://docs.mongodb.com/manual/reference/operator/aggregation/sum/ – Jackstine