简体   繁体   English

PyMongo 驱动程序是否聚合数据

[英]Does the PyMongo driver aggregate data

...after it retrieves all of it from MongoDB and transferring it over the network? ...在它从 MongoDB 检索所有内容并通过网络传输之后?

What I'm trying to ask is - in a traditional DB scenario, the COUNT, SUM etc are performed at the DB end.我想问的是 - 在传统的数据库场景中,COUNT、SUM 等是在数据库端执行的。 Does PyMongo transfer all the records over the network and then do the aggregation? PyMongo 是否通过网络传输所有记录然后进行聚合?

For example, I'm looking at the query from PyMongo's tutorial : posts.find({"author": "Mike"}).count()例如,我正在查看PyMongo 教程中的查询: posts.find({"author": "Mike"}).count()

The count() method of pymongo.cursor.Cursor actually sends a 'count' command to the server that only returns the count, not the documents. pymongo.cursor.Cursor 的 count() 方法实际上向服务器发送了一个“count”命令,该命令只返回计数,而不是文档。 You can do the same thing yourself:你可以自己做同样的事情:

>>> 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}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM