Mongodb has different authentication mechanisms. After version 3.0, mongodb-cr is used, while before version, mongodb-cr is used
So, in my version, it’s obvious that ‘scratch-sha-1’ should be used
from pymongo import MongoClient
host = '127.0.0.1'
client = MongoClient(host, 27017)
# connect to mydb database, account password authentication
db = client.admin # first connect to the system default database admin
# The following change is the key, I can not believe I tried successfully, I do not know why, first record the pit it stepped on
db.authenticate("root", "123456",mechanism='SCRAM-SHA-1') # let the admin database to authenticate the password login, well, since the success of
my_db = client.mydb # then connect to their own database mydb
collection = my_db.myset # myset collection, as explained above
collection.insert({"name": "zhangsan", "age":18}) # insert a data, if there is no error then the successful connection
for i in collection.find():
print(i)
Similar Posts:
- [Solved] TypeError: ‘Collection’ object is not callable. If you meant to call the ‘authenticate’ method on a ‘Database’ object it is failing because no such method exists.
- Mongovue is unable to create collections and log in with user name and password
- mongodb:E QUERY [thread1] SyntaxError: missing ; before statement @(shell):1:4
- Mongodb access control is not enabled for the database
- Error occurred when using java to connect mongodb: command failed with error 18 (authentication failed): “authentication failed.”
- [Solved] Mongodb Error: NETWORK [thread1] Failed to connect to 127.0.0.1:27017
- MySQL database insert into statement with parameters Error
- Raspberry pie: How to Solve Mongodb installation error
- mongodb not authorized on admin to execute command [version 3.2.18]
- [Solved] Brew Install MongoDB Error: “Error: No available formula with the name “mongodb””