我使用python与pymongo。得到计数,并将它们分组
在mongo集合中保存来自不同国家的不同消息。 每个文件都有一个国家短代码来表示他们的国家。 我可以知道如何将他们分组并获得每个国家代码的计数?
例如
{u'tweet': u"If you're male and own an iPhone, get new star soccer. Holy shit it's addictive", u'loc': u"US", u'_id': ObjectId('515ecace4e18187ca67ddfcb'), u'time': datetime.datetime(2013, 4, 5, 12, 59, 57)}
以上是与位置信息的一行,并在我的数据库可能有美国,SG,AU等等...不同的位置会有不同的邮件数量。我如何查询或是任何可能的方法?由于
UPDATE
我想计数的原因是因为我需要将数据注入到下面的代码google chart generate the chart我。
var data = google.visualization.arrayToDataTable([
['Country', 'Popularity'],
['Germany', 200],
['United States', 300],
['Brazil', 400],
['Canada', 500],
['France', 600],
['RU', 700]
]);
http://docs.mongodb.org/manual/reference/aggregation/group/ – dm03514 2013-04-05 13:30:49