简体   繁体   English

通过RoboMongo进行MongoDB远程连接

[英]MongoDB remote connection via RoboMongo

I'm trying to connect to my Mongodb server via Robomongo. 我正在尝试通过Robomongo连接到我的Mongodb服务器。

I have changed the Bind_ip to 0.0.0.0 at the server mongod.conf I have also set the auth=true field. 我已经改变了Bind_ip0.0.0.0在服务器mongod.conf我还设置了auth=true场。

Now when I'm trying to log in from RoboMongo I'm getting auth fail error. 现在,当我尝试从RoboMongo登录时,我收到了auth fail错误。

To be honest i have no idea what is the user name or password (I didn't set any user after installing Mongo, and i prefer not to because I'm using nodeJs to query the db and when i try to log in I'm getting auth fail as well [thats with mongoskin]) 说实话,我不知道用户名或密码是什么(安装Mongo后我没有设置任何用户,我不喜欢,因为我使用nodeJs来查询数据库,当我尝试登录时我' m得到auth失败[那与mongoskin])

Does Mongodb have default user name or password? Mongodb是否有默认用户名或密码? or what else can I do? 或者我还能做什么?

Does Mongodb have default user name or password? Mongodb是否有默认用户名或密码?

There are no default users created by MongoDB, however if you have just enabled authentication and haven't created your first user yet (which should be a user administrator), then you have to connect via localhost to set up up the initial user. MongoDB没有创建默认用户,但是如果您刚刚启用了身份验证并且尚未创建第一个用户 (应该是用户管理员),则必须通过localhost连接才能设置初始用户。 There is a localhost exception enabled by default to specifically to allow creation of the first user with auth enabled. 默认情况下启用localhost异常以专门允许创建启用了auth的第一个用户。 Remote connections will not be able to authenticate without valid user credentials. 没有有效的用户凭据,远程连接将无法进行身份验证。

After you have created the required user(s) , you should then be able to login remotely with those credentials using Robomongo or another interface like the mongo shell or your mongoskin app. 创建所需用户后 ,您应该能够使用Robomongo或其他界面(如mongo shell或mongoskin应用程序)远程登录这些凭据。

If you don't want to use the localhost exception an alternative approach would be to start your MongoDB server with auth disabled, add the required users remotely, and then restart the server with auth enabled. 如果您不想使用localhost异常,则另一种方法是在禁用auth的情况下启动MongoDB服务器,远程添加所需用户,然后在启用auth的情况下重新启动服务器。

All you need is in the docs: http://docs.mongodb.org/manual/tutorial/enable-authentication/ 所有你需要的是在文档中: http//docs.mongodb.org/manual/tutorial/enable-authentication/

Create admin user (role): 创建管理员用户 (角色):

use admin
db.createUser(
  {
    user: "siteUserAdmin",
    pwd: "password",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

Add normal users (read write role): 添加普通用户 (读写角色):

use reporting
db.createUser(
    {
      user: "reportsUser",
      pwd: "12345678",
      roles: [
         { role: "read", db: "reporting" },
         { role: "read", db: "products" },
         { role: "read", db: "sales" },
         { role: "readWrite", db: "accounts" }
      ]
    }
)

To add the admin, you probably need to start mongo using auth=false , add adminuser, and re-enable auth=true . 要添加管理员, 您可能需要使用auth=false启动mongo ,添加adminuser,然后重新启用auth=true

To view roles : db.getRoles() 查看角色db.getRoles()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM