While Creating New User in MongoDB, it has to be c

2020-05-21 04:51发布

问题:

I want to create a new user in MongoDB, So i have to do that by login to admin by(use admin) and then i have to use the command add user to create new user is it?

Thanks,

回答1:

If no users created you can create new user without any authentification, but if you have created admin user for specific database you should authentifcate, and then perform any operation.

Documentation:

If no users are configured in admin.system.users, one may access the database from the localhost interface without authenticating. Thus, from the server running the database (and thus on localhost), run the database shell and configure an administrative user:

 $ ./mongo
 > use admin
 > db.addUser("theadmin", "anadminpassword")

We now have a user created for database admin. Note that if we have not previously authenticated, we now must if we wish to perform further operations, as there is a user in admin.system.users.

 > db.auth("theadmin", "anadminpassword")

We can view existing users for the database with the command:

 > db.system.users.find()

Now, let's configure a "regular" user for another database.

 > use projectx
 > db.addUser("joe", "passwordForJoe")


标签: mongodb