pymongo.errors.OperationFailure:错误

时间:2011-01-04 08:18:55

标签: python mongodb pymongo

我在不同的mongod上使用不同的port开始了3 dbpath个处理。

./bin/mongod --replSet foo/tauquir:27018,tauquir:27019 --rest
./bin/mongod --port 27018 --dbpath /data/db1 --replSet foo/tauquir:27017 --rest
./bin/mongod --port 27019 --dbpath /data/db2 --replSet foo/tauquir:27017 --rest

开始连接:

CONN = Connection("tauquir:27017", slave_okay=True)
CONN.admin.command("replSetInitiate")
CONN = Connection(["tauquir:27018", "tauquir:27019"])

追溯我得到了:

     CONN.admin.command("replSetInitiate")
              File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-
        i686.egg/pymongo/database.py", line 293, in command msg, allowable_errors)
              File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux- 
    i686.egg/pymongo/helpers.py", line 119, in _check_command_response raise 
OperationFailure(msg % response["errmsg"])
            pymongo.errors.OperationFailure: command SON([('replSetInitiate', 1)]) failed: 

all members and seeds must be reachable to initiate set

1 个答案:

答案 0 :(得分:1)

replSetInitiate是一次性命令,因此您可能不希望使用您的连接init编码,但在该行之后您需要使用所有3个mongod服务器的连接信息来实例化您的python客户端。

在您的示例中,您将CONN变量替换为仅连接到27018和27019

db = Connection(["tauquir:27017", "tauquir:27018", "tauquir:27019"])