By default Mongo is accepting connections without authentication. If, you want to enable authentication, you can add the users to the admin database.
Example: Create a user named root with password test
db.createUser(
{
user: "root",
pwd: "test",
roles: ['clusterAdmin', 'userAdminAnyDatabase', 'readWriteAnyDatabase']
}
)
You can check the users of current database with the command
db.createUser(
{ user: "testuser_1",
pwd: "testpass",
roles: [ "read" ]
} )
db.createUser(
{ user: "testuser_2",
pwd: "testpass",
roles: [ "readWrite" ]
} )
db.createUser(
{ user: "someAdmin",
pwd: "verysecretpassword",
roles: [ "readWrite","dbAdmin" ]
} )
And if you want to create a admin user which has priveleges to all databases
use admin
db.createUser(
{ user: "theAdmin",
pwd: "verysecretpassword",
roles: ['clusterAdmin', 'userAdminAnyDatabase', 'readWriteAnyDatabase']
} )