search

Home  >  Q&A  >  body text

node.js - mongodb中的数据库权限

我在数据库的admin中创建了一个管理员,角色是root,其他普通数据库都没创建,可用mongoose连接普通数据库example怎么都连接不上,说not authorized on example to execute command ,加上admin的用户名和密码也无法登陆,报错为Authentication failed。求大佬告知怎么改。

巴扎黑巴扎黑2782 days ago580

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-17 15:41:21

    1. The admin username and password cannot log in, and the error is Authentication failed.

    When logging in as an administrator (your configured role is root), please configure authenticationDatabase "admin"; for example, in the mongo command line:

    mongo -u "root" -p "root" --authenticationDatabase "admin"

    2. You can use mongoose to connect to the ordinary database example but cannot connect, saying not authorized on example to execute command

    The correct step is to use the administrator to create the database user required for the application, assign permissions, and then log in. For example:

    Create user/assign permissions, specify user name, permissions, and corresponding database, for example, on the command line:
    db.createUser(
    {

    user: "app",
    pwd: "app",
    roles: [ { role: "readWrite", db: "example" } ]

    }
    )

    When logging in, connect to the example database, for example, from the command line:

    mongo -u "app" -p "app" --authenticationDatabase "example"

    For reference.

    Love MongoDB! Have Fun!

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 15:41:21

    I just encountered this problem recently, you can take a look at this http://kdylan.me/2016/12/11/m...

    reply
    0
  • Cancelreply