【问题标题】:TypeError occurs when trying to enable Mongo DB authentication尝试启用 Mongo DB 身份验证时发生 TypeError
【发布时间】:2014-04-12 19:04:23
【问题描述】:

我正在尝试启用 Mongo DB 身份验证的 step 3。当我尝试完全按照说明通过 Mongo shell 创建用户时,shell 报告:

TypeError: 对象 admin 的属性“createUser”不是函数

我使用 --auth 选项启动 mongod 并切换到 admin 数据库。一如既往,感谢您的帮助。

【问题讨论】:

    标签: mongodb mongodb-shell


    【解决方案1】:

    如果您使用的是 Mongo 2.4 或更早版本,请使用 addUser 而不是 createUser

    Mongo 2.4

    将此(如 here 提到的)用于读写用户以及 dbAdmin 角色:

    db.addUser( { user: "joe",
                  pwd: "secret",
                  roles: [ "readWrite", "dbAdmin" ]
                } )
    

    对于只读用户:

    db.addUser( { user: "joe",
                  pwd: "secret",
                  roles: [ "read" ]
                } )
    

    (查看所有可能的用户角色here。)

    Mongo 2.2

    对于提到的读/写用户here

    use mydb;
    db.addUser("joe", "secret");
    

    对于提到的只读用户here

    use mydb;
    db.addUser("joe", "secret", true);
    

    【讨论】:

      【解决方案2】:

      问题是我试图针对显然不受支持的 mongod 2.4.9 执行此功能。在 2.6.0 版本中不会出现此错误消息。

      【讨论】:

      • 这个错误实际上似乎是由mongo的版本引起的,即CLI,也使用了。 2.6 版 mongod 上的 2.4 版客户端也会导致此错误。
      猜你喜欢
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-22
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      • 2019-11-19
      相关资源
      最近更新 更多