I am writing code using pymongo that uses an aggregation structure to store some data in another collection. The code looks like this:
from pymongo import MongoClient
def makeAggregate():
print 'Making aggregation of commits..'
commitsCollection = MongoClient("mongo-srv", 27017).gt.commits
rankingCollection = MongoClient("mongo-srv", 27017).gt.commitsRanking
pipe = [{'$unwind': '$commits'},{'$group':{"_id":"$_id", "picture": {"$first": "$picture"},'a':{'$sum':'$commits.a'},'d':{'$sum':'$commits.d'},'c':{'$sum':'$commits.c'}}}]
cursor = commitsCollection.aggregate(pipeline=pipe)
obj = next(cursor, None)
while obj:
rankingCollection.save(obj)
obj = next(cursor, None)
makeAggregate()
The code works fine on my computer, but when I moved the script to the server, the script failed, saying:
Traceback (most recent call last):
File "aggregate.py", line 17, in <module>
makeAggregate()
File "aggregate.py", line 12, in makeAggregate
obj = next(cursor, None)
TypeError: dict object is not an iterator
Command python --version
returns
On my computer:
Python 2.7.3
On server
Python 2.7.6
Command pip show pymongo
returns
On my computer:
Usage: pip COMMAND [OPTIONS]
pip: error: No command by the name pip show
(maybe you meant "pip install show")
(Done pip install show
, but continues to talk about it when running show ..)
On server:
Name: pymongo
Version: 2.7
Location: /usr/local/lib/python2.7/dist-packages/pymongo-2.7-py2.7-linux-x86_64.egg
Requires:
Running pymongo.version
inside python gives me:
In my computer:
3.0
On server
2.7
Maybe I need to update this? How can i do this?