[DOCS-6665] Comment on: "primer/aggregation.txt" Created: 28/Nov/15  Updated: 03/Nov/17  Resolved: 29/Mar/16

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: Docs Collector User (Inactive) Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OSX, python3

Location: https://docs.mongodb.org/getting-started/python/aggregation/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.7
Referrer: https://docs.mongodb.org/getting-started/python/remove/
Screen Resolution: 1920 x 1080
repo: docs
source: aggregation


Participants:
Days since reply: 7 years, 46 weeks, 2 days ago

 Description   

The examples on this page do not seem to work properly.

They just return "result ok".

>>> cursor = db.restaurants.aggregate(
... [
... {"$group": {"_id": "$borough", "count":

{"$sum": 1}

}}
... ]
... )
>>> for document in cursor:
... print(document)
...
result
ok
>>> cursor = db.restaurants.aggregate(
... [
... {"$match": {"borough": "Queens", "cuisine": "Brazilian"}},
... {"$group": {"_id": "$address.zipcode", "count":

{"$sum": 1}

}}
... ]
... )
>>> for document in cursor:
... print(document)
...
result
ok
>>>



 Comments   
Comment by Kay Kim (Inactive) [ 29/Mar/16 ]

Hi – thank you for filing the ticket. I believe the documentation is correct as since PyMongo v3.0 aggregate method returns a CommandCursor (see API)

>>> cursor = db.restaurants.aggregate(
...     [
...         {"$group": {"_id": "$borough", "count": {"$sum": 1}}}
...     ]
... )
>>> 
>>> print cursor
<pymongo.command_cursor.CommandCursor object at 0x100b63f90>
>>> if cursor['ok'] == 1:
...   print cursor
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'CommandCursor' object has no attribute '__getitem__'

To verify the version of PyMongo:

>>> import pymongo
>>> pymongo.__version__
'3.2.2'

Generated at Thu Feb 08 07:52:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.