Creating a Database Administrator Account

You create a database administrator account by executing the addUser method in the MongoDB shell to access the admin database. Then you add a user with readWriteAny-Database, dbAdminAnyDatabase, and clusterAdmin rights. This gives that user the ability to access all databases in the system, create new databases, and manage MongoDB clusters and replicas. The following example creates a database administrator named dbadmin:

use admin
db.addUser( { user: "dbadmin",
    pwd: "test",
    roles: [ "readWriteAnyDatabase", "dbAdminAnyDatabase", "clusterAdmin" ] } )

You can then use that user in the MongoDB shell to administer databases. Once you have created the new administrator account, you can authenticate as that user by using the following commands:

use admin
db.auth("dbadmin", "test")

You can also authenticate to the admin database as the database administrator when starting the MongoDB shell by using the --username and --password options, as in this example:

mongo admin --username "dbadmin" --password "test"

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.2.137