尝试将记录插入mongo集合时出现身份验证错误

时间:2018-08-21 05:37:03

标签: mongodb pymongo

以下是我使用的版本:

Python == 3.6.4

Mongo DB数据库版本== v4.0.0

Pymongo版本== 3.7.1

问题

使用相同的连接字符串,我可以在mongo db上执行以下操作

a)连接到数据库

b)获取集合名称

连接字符串的格式为mongodb://<username>:<password>@localhost:27017/?authMechanism=SCRAM-SHA-1&authSource=<dbName>

当我尝试使用collection.insert_one()方法将记录插入同一集合时,出现以下错误 pymongo.errors.OperationFailure: Authentication failed

使用mongo shell db.insert方法时,我可以使用同一用户插入记录。

0 个答案:

没有答案
相关问题