mongodb 尝试启用 Mongo DB 身份验证时发生 TypeError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23034841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 13:40:35  来源:igfitidea点击:

TypeError occurs when trying to enable Mongo DB authentication

mongodbmongodb-shell

提问by danny-v

I'm on step 3of trying to enable Mongo DB authentication. When I try to create a user via the Mongo shell exactly as the directions indicate, the shell reports:

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

TypeError: Property 'createUser' of object admin is not a function

类型错误:对象 admin 的属性“createUser”不是函数

I started mongod with the --auth option and switched to the admin database. as always, help appreciated.

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

采纳答案by danny-v

The issue was I was trying to execute this function against mongod 2.4.9 which apparently isn't supported. This error message does not occur in the 2.6.0 release.

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

回答by arun

If you are using Mongo 2.4 or earlier versions, then use addUserinstead of createUser.

如果您使用的蒙戈2.4或更早的版本,然后使用addUser代替createUser

Mongo 2.4

蒙戈 2.4

Use this (as mentioned here) for a read and write user along with dbAdmin role:

使用这个(提到这里),与dbAdmin角色沿读取和写入的用户:

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

For a read-only user:

对于只读用户:

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

(See all possible user roles here.)

在此处查看所有可能的用户角色。)

Mongo 2.2

蒙戈 2.2

For a read/write user as mentioned here:

对于这里提到的读/写用户:

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

For a read-only user as mentioned here:

对于此处提到的只读用户:

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