MongoDB User Authorization and management

Source: Internet
Author: User
Tags auth mongo shell

1, MongoDB installed after the first entry is not required password, and no user, through the shell command can directly enter, CD to the MongoDB Directory Bin folder, execute the command./mongo can be run as follows:
 [ [email protected] MongoDB  Span style= "COLOR: #ff0000" >]  #. / bin/  Mongomongodb Shell version:  1.8 . 2  connecting  to  : Test  >  use   test;switched  to  DB test 
 2, add Admin user (MongoDB does not have invincible user root, only can manage user's user useradminanydatabase), >use admin>db.createuser ( {user: " Admin ", pwd:" 123456 ", roles: [{role:" Useradminanydatabase ", DB:" Admin "}]}) Note: You can use show when you have finished adding users When users or Db.system.users.find () view existing user  3, add admin users, turn off MongoDB, and use permission mode to open MongoDB again, note that you should not use Kill to kill the MongoDB process directly. (If you do, go to the data/db directory to delete the Mongo.lock file), you can use Db.shutdownserver () to turn off  4, use permissions to start Mongodb./mongod--dbpath=/usr/ Local/mongodb/data--logpath=/usr/local//mongodb/mongod.log--fork --auth or modified in config file:  auth = True#noauth = True 5, enter the MONGO shell, use the admin database and verify, if not verified, can not do any operation.  > use admin> db.auth ("admin", "123456")   #认证, returns 1 for successful  6, after validation, or not, because admin only has user administrative rights, create user below, The user follows the vault,> use mydb> db.createuser ({User: "root", pwd: "123456", roles: [{role: "ReadWrite", DB: "MyDB"}]})  7, make Database operation with user root login created: [[email protected] mongodb]# MONGO 127.0.0.1/mydb-uroot-pmongodb Shell Version:3.2.9enter Password:connecting to:127.0.0.1/mydb> dbmydb> Use mydbswitched to DB mydb> show collections  then you can do a variety of data manipulation ...

MongoDB user authorization and administration

Related Article

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.