我尝试将文档插入到复制的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
答案 0 :(得分:0)
如果
,则有效client = MongoClient('mongodb://user01:12345678@10.77.14.231,10.77.14.232,10.77.14.233,10.77.14.234/TDB01')