Story background:
I set up a MONGO database on the virtual machine (ip:192.168.xx.xx), and the contents are already stored. Inside a database called "adb", there is a collection, called "Acol"
I turned on MONGO's authentication feature and granted the user "UserA" access to "adb".
Then I connect it in the following way
Import'192.168.xx.xx'= Pymongo. Mongoreplicasetclient ('mongodb://%s:%[email protected]%s' %= conn[" adb"= db["acol"]
Result Error:
Pymongo.errors.OperationFailure:command SON ([' Authenticate ', 1), (' User ', U '), (' Nonce ', U '), (' Key ', U ')]) on names Pace Admin. $cmd Failed:auth Failed
Then, all sorts of entanglements. Later saw the official website, finally found a solution.
Http://api.mongodb.org/python/current/examples/authentication.html
1. View Pymongo Version: result is 3.2
Pip List-v
2. View MongoDB version: result is 2.6
Enter in the MONGO terminal
Db.version ()
MONGODB has a different authentication mechanism, the 3.0 version after the adoption of ' Scram-sha-1 ', the previous version of the use of ' MONGODB-CR '. So, in my version case, it's obvious that you should use ' MONGODB-CR '
Use the following method to connect, it succeeds.
' 192.168.xx.xx ' = Pymongo. Mongoclient (host) client.adb.authenticate ("UserA", "password", mechanism='mongodb-cr' = = db["Acol"]
"Pymongo" Connection authentication Auth failed solution