I am writing a code using pymongo which uses the aggregation framework to save some data in other collection. The code is 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 a server, then 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
The command python --version
returns
On my computer:
Python 2.7.3
On the server
Python 2.7.6
The 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")
(Executed pip install show
but keeps saying this when running show..)
On the 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
In the server
2.7
Maybe I have to update this? How can I do that?