【发布时间】:2015-10-03 10:32:17
【问题描述】:
我正在使用 pymongo 编写代码,它使用聚合框架将一些数据保存在其他集合中。 代码是这样的:
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()
代码在我的计算机上运行良好,但是当我将脚本移动到服务器时,脚本失败了,说:
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
python --version 命令返回
在我的电脑上:
Python 2.7.3
在服务器上
Python 2.7.6
pip show pymongo 命令返回
在我的电脑上:
Usage: pip COMMAND [OPTIONS]
pip: error: No command by the name pip show
(maybe you meant "pip install show")
(执行pip install show,但在运行节目时一直这么说..)
在服务器上:
Name: pymongo
Version: 2.7
Location: /usr/local/lib/python2.7/dist-packages/pymongo-2.7-py2.7-linux-x86_64.egg
Requires:
在 python 中运行 pymongo.version 给了我:
在我的电脑中:
3.0
在服务器中
2.7
也许我必须更新这个?我该怎么做?
【问题讨论】:
-
你能给本地和服务器机器的 Pymongo、MongoDB 版本吗?
-
@imagin 我写了
python --version给出的内容,并且在两种情况下使用的mongo服务器都是相同的。您是否还要求别的东西? -
是的 PyMongo 和 MongoDB 版本
-
您能否尝试关注以检查实际查看
import pymongo后跟pymongo.version的pymongo python 版本?您也可以在 python 命令行上为本地计算机和服务器运行它。 -
@Satarangi_Re 刚刚用版本更新了帖子,问题可能出在我的版本是 3.0 而服务器的版本是 2.7。也许我必须更新它?我该怎么做?