Get the App
SLTechnology News&Howtos  ›  Database  › 

How to modify the database authentication mechanism in MongoDB3.0

Shulou Source: shulou.com Published: 2022-05-31 21:13:48 09月11日 Update

This article introduces you how to modify the database authentication mechanism in MongoDB3.0, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Modification requirements: MongoDB3.0 's current authentication mechanism is SCRAM-SHA-1, which needs to be changed to the old authentication mechanism MONGODB-CR.

The methods are as follows:

> use admin

Switched to db admin

> db.system.version.findOne ({"_ id": "authSchema"})

{"_ id": "authSchema", "currentVersion": 5}

A currentVersion of 5 means that the authentication mechanism of the current database is SCRAM-SHA-1, which needs to be changed to a value of 3 for MONGODB-CR,currentVersion.

> var schema = db.system.version.findOne ({"_ id": "authSchema"})

> schema.currentVersion = 3

three

> db.system.version.save (schema)

WriteResult ({"nMatched": 1, "nUpserted": 0, "nModified": 1})

> db.system.version.find ()

{"_ id": "authSchema", "currentVersion": 3}

Here it means that the modification has been successful.

Create a database user

> use test

> db.createUser ({user: 'test', pwd:' test123', roles: [{role: "readWrite", db: "test"}]})

Successfully added user: {

"user": "test"

"roles": [

{

"role": "userAdminAnyDatabase"

"db": "admin"

}

]

View the authentication method:

> use admin

> db.system.users.find ()

{"_ id": "admin.admin", "user": "admin", "db": "admin", "credentials": {"SCRAM-SHA-1": {"iterationCount": 10000, "salt": "kAyNTjjA56SjKNB+voW/ow==", "storedKey": "S0QMFvrojLTl4fYN4zz6HL3rlRc =", "serverKey": "m0eym4YQikIufcR8JxcIRfdDrg ="}, "roles": [{"role": "userAdminAnyDatabase" "db": "admin"}]}

{"_ id": "test.test", "user": "test", "db": "test", "credentials": {"MONGODB-CR": "cf75a14725e3655983a84ea5f5b25438"}, "roles": [{"role": "readWrite", "db": "test"}]}

On how to modify the database authentication mechanism in MongoDB3.0 to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Authentication mechanism data database content more help good success interest guys partners articles methods methods users knowledge articles requirements references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Linux Docker macOS Microsoft