mongo
use admin db.createUser( { user: "mongoadmin", pwd: "dbadmin@123", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } )
mongod --auth --port 27017 --dbpath /data/db1
Create Super User
use admin db.createUser( { user: "mongoroot", pwd: "root@123", roles: ["root"] } )
SELECT RIGHT USER
use twitter db.createUser( { user: "selectuser", pwd: "xyz123", roles: [{ role: "read", db: "twitter" } ] } Successfully added user: { "user" : "selectuser", "roles" : [ { "role" : "read", "db" : "twitter" } ] } > show users; { "_id" : "twitter.selectuser", "user" : "selectuser", "db" : "twitter", "roles" : [ { "role" : "read", "db" : "twitter" } ] } ------ > db.auth("selectuser","xyz123") 1 ------OR-------- mongo --port 27017 -u "selectuser" -p "xyz123" --authenticationDatabase "twitter" ------CHANGE PASSWORD-------- use twitter db.changeUserPassword("selectuser","admin@123") ----LOGIN AGAIN------ mongo --port 27017 -u "selectuser" -p "admin@123" --authenticationDatabase "twitter" use twitter
---CREATE SUPER USER----- use admin db.createUser({user : "mongo",pwd:"mongo",roles:["root"]}) Successfully added user: { "user" : "mongo", "roles" : [ "root" ] }
> db.auth(“mongo”,”mongo”)
1
OR
mongo --port 27017 -u "mongo" -p "mongo" --authenticationDatabase "admin"
> show dbs;
admin 0.000GB
local 0.000GB
twitter 0.719GB
viva 0.061GB
> use twitter
switched to db twitter
> show collections
docs
jalikatu
kashmir
northkorea
repo
repo2
repo3
repo4
sahpur
sahpurextract
total
twitte2