简体   繁体   中英

Does the PyMongo driver aggregate data

...after it retrieves all of it from MongoDB and transferring it over the network?

What I'm trying to ask is - in a traditional DB scenario, the COUNT, SUM etc are performed at the DB end. Does PyMongo transfer all the records over the network and then do the aggregation?

For example, I'm looking at the query from PyMongo's tutorial : 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. 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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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