MONGO management user related operations summary _mongodb

Source: Internet
Author: User
Tags auth mongo shell

List all Users

Copy Code code as follows:

Mongo
Use admin
Db.system.users.find ()

Disabling authentication Mode

Copy Code code as follows:

/etc/mongod.conf
Noauth = True
Auth = False

Create a user

The user is database based and the user created on the admin database belongs to the administrator user.

Creation of managers ' users

Users who have all the database administrative permissions

Copy Code code as follows:

Use admin
Db.createuser ({
User: "username"
PWD: "Password"
Roles: [
{
Role: "Useradminanydatabase"
DB: "Admin"
}
]
})

users with specific database administrative permissions
Copy Code code as follows:

Use "Database name"
Db.createuser ({
User: "username",
PWD: "Password",
Roles: [
{
Role: "Useradmin",
DB: "Database name"
}
]
})

General User
Copy Code code as follows:

DB "Database name"
Db.createuser ({
User: "username",
PWD: "Password",
Roles: [
{
Role: "read", # or "ReadWrite"
DB: "Database name",
}
]
})

user authentication
Copy Code code as follows:

Db.auth ("username", "password")
MONGO Shell-initiated validation
$ MONGO "database name"-U "username"-P "password"

Delete User

Copy Code code as follows:

Use "Database name"
Db.system.users.remove ({User: "username to delete}")

Example: Create a database user with read and write access to the data

Create a database user with read and write access to the database

Copy Code code as follows:

Use dbname;
Db.createuser ({User: "Dbuser", pwd: "Dbuseradmin", Roles:[{role: "ReadWrite", DB: "DBName"}]})

Database User Login
Copy Code code as follows:

MONGO Dbname-u dbuser-p dbduseradmin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.