pymongo.errors.OperationFailure:数据库错误:ns无效

时间:2015-06-20 18:43:42

标签: python mongodb insert pymongo

我尝试将文档插入到复制的Mongo数据库中:

>>> from pymongo import MongoClient
>>> client = MongoClient('mongodb://user01:12345678@10.77.14.231,10.77.14.232,10.77.14.233,10.77.14.234/TDB01/?replicaSet=trepl')
>>> db=client.TDB01
>>> ts01 = db.tc01
>>> ts01.insert_one({'a':1})
...
pymongo.errors.OperationFailure: database error: Invalid ns [TDB01/.$cmd]

trepl:PRIMARY> use TDB01
switched to db TDB01
trepl:PRIMARY> db.tc01.insert({'name':'Petr'})
WriteResult({ "nInserted" : 1 })

在复制数据库之前,python代码已经运行了。

我有pymongo(3.0.2)和mongodb 3.0.4

1 个答案:

答案 0 :(得分:0)

如果

,则有效
client = MongoClient('mongodb://user01:12345678@10.77.14.231,10.77.14.232,10.77.14.233,10.77.14.234/TDB01')