在MongoDB中创建新用户时,必须在admin下创建它? [英] While Creating New User in MongoDB, it has to be created under admin?

查看:1021
本文介绍了在MongoDB中创建新用户时,必须在admin下创建它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MongoDB中创建一个新用户,所以我必须通过登录到admin by(使用admin)来做到这一点,然后我必须使用命令add user来创建新用户吗?

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?

谢谢

推荐答案

如果没有创建任何用户,则可以在不进行任何身份验证的情况下创建新用户,但是如果您为特定数据库创建了admin用户,则应该进行身份验证,然后执行任何操作.

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:

如果未在其中配置任何用户 admin.system.users,一个人可以访问 来自localhost接口的数据库 未经身份验证.因此,从 服务器运行数据库(因此 在localhost上),运行数据库shell 并配置管理用户:

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")

我们现在为创建了一个用户 数据库管理员.请注意,如果我们有 以前未通过身份验证,我们现在 如果我们希望进一步执行,则必须 操作,因为其中有一个用户 admin.system.users.

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中创建新用户时,必须在admin下创建它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆