mongodb user code example
Example 1: mongodb create user
use admin
db.createUser(
{
user: "restricted",
pwd: passwordPrompt(), // Or "<cleartext password>"
roles: [ { role: "readWrite", db: "reporting" } ],
authenticationRestrictions: [ {
clientSource: ["192.0.2.0"],
serverAddress: ["198.51.100.0"]
} ]
}
)
Example 2: mongo db shell user login
$ mongo admin -u uname -p 'password'