...在从MongoDB中检索所有内容并通过网络传输之后?

我要问的是-在传统的数据库方案中,COUNT,SUM等在数据库端执行。 PyMongo是否通过网络传输所有记录,然后进行汇总?

例如,我正在查看来自PyMongo's tutorial的查询:posts.find({"author": "Mike"}).count()

最佳答案

pymongo.cursor.Cursor的count()方法实际上向服务器发送一个“ count”命令,该命令仅返回计数,而不返回文档。您可以自己做同样的事情:

>>> db = c.foo
>>> for doc in db.things.find(): print doc
...
{u'_id': ObjectId('4de671821121812a0087101b'), u'foo': u'bar'}
{u'_id': ObjectId('4de671ea1121812a0087101c'), u'buzz': u'baz'}

>>> db.command('count', 'things', query={'foo': 'bar'})
{u'ok': 1.0, u'n': 1.0}

关于python - PyMongo驱动程序是否聚合数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6204407/

10-09 20:16
查看更多