我在 MongoDB 中有一个 ISSUES 的数据库,其中一些 issue 有评论,这是一个数组;每个评论都有一个作者。我如何计算每个作者写的评论数量?
我试过了
db.test.issues.group(
{
key = "comments.username":true;
initial: {sum:0},
reduce: function(doc, prev) {prev.sum +=1},
}
);
但没有运气:(
一个样品:
{
"_id" : ObjectId("50f48c179b04562c3ce2ce73"),
"project" : "Ruby Driver",
"key" : "RUBY-505",
"title" : "GETMORE is sent to wrong server if an intervening query unpins the connection",
"description" : "I've opened a pull request with a failing test case demonstrating the bug here: https://github.com/mongodb/mongo-ruby-driver/pull/134\nExcerpting that commit message, the issue is: If we do a secondary read that is large enough to require sending a GETMORE, and then do another query before the GETMORE, the secondary connection gets unpinned, and the GETMORE gets sent to the wrong server, resulting in CURSOR_NOT_FOUND, even though the cursor still exis ts on the server that was initially queried.",
"status" : "Open",
"components" : [
"Replica Set"
],
"affected_versions" : [
"1.7.0"
],
"type" : "Bug",
"reporter" : "Nelson Elhage",
"priority" : "major",
"assignee" : "Tyler Brock",
"resolution" : "Unresolved",
"reported_on" : ISODate("2012-11-17T20:30:00Z"),
"votes" : 3,
"comments" : [
{
"username" : "Nelson Elhage",
"date" : ISODate("2012-11-17T20:30:00Z"),
"body" : "Thinking some more"
},
{
"username" : "Brandon Black",
"date" : ISODate("2012-11-18T20:30:00Z"),
"body" : "Adding some findings of mine to this ticket."
},
{
"username" : "Nelson Elhage",
"date" : ISODate("2012-11-18T20:30:00Z"),
"body" : "I think I tracked down the 1.9 dependency."
},
{
"username" : "Nelson Elhage",
"date" : ISODate("2012-11-18T20:30:00Z"),
"body" : "Forgot to include a link"
}
]
}