Mongodb 在创建新用户时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51149455/
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
Mongodb getting error while creating new user
提问by Aman Bansal
I just installed a fresh mongodb on Ubuntu server and when i try to adduser i am getting error
我刚刚在 Ubuntu 服务器上安装了一个新的 mongodb,当我尝试添加用户时出现错误
db.createUser(
{
user: "admin",
pwd: "ADYkdfd332@@33",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
2018-07-03T13:29:41.556+0530 E QUERY [thread1] Error: couldn't add user: Use of SCRAM-SHA-256 requires undigested passwords :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1
回答by user9681090
This works for me:
这对我有用:
db.createUser({
user:"test1",
pwd:"test1",
roles:[
{
role:"readWrite",
db:"u8"
}
],
mechanisms:[
"SCRAM-SHA-1"
]
})
回答by Dolynskiy Eduard
If you use User Management Methodsyou have to set param passwordDigestor
.
如果您使用用户管理方法,则必须设置 param passwordDigestor
。
db.createUser(
{
user: "admin",
pwd: "ADYkdfd332@@33",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ],
passwordDigestor: "<server|client>"
}
)
回答by Abhay
Go with following commands in Mongo Shell:
在 Mongo Shell 中使用以下命令:
use admin
db.createUser({
user:"admin",
pwd:"abc123",
roles:[{role:"userAdminAnyDatabase",db:"admin"}],
passwordDigestor:"server"
})
Further you can refer enable authentication
此外,您可以参考启用身份验证
回答by Mohammad Raheem
回答by Sohail Ahmed
This error comes up only when you are accessing it remotely.
仅当您远程访问它时才会出现此错误。
If passwordDigestor
is client then mechanisms
is not compatible with SCRAM-SHA-256
and only SCRAM-SHA-1
can be used.
如果passwordDigestor
是客户端mechanisms
则不兼容,SCRAM-SHA-256
只能SCRAM-SHA-1
使用。
use admin
db.createUser(
{
user: "username",
pwd: "password",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ],
mechanisms: [ "SCRAM-SHA-1" ],
passwordDigestor: "client"
}
)
If passwordDigestor
is server then both mechanisms
i.e. SCRAM-SHA-1
and SCRAM-SHA-256
can be used or it works even if you don't specify it at all.
如果passwordDigestor
是服务器,则mechanisms
ieSCRAM-SHA-1
和SCRAM-SHA-256
都可以使用,或者即使您根本不指定它也可以工作。
use admin
db.createUser(
{
user: "username",
pwd: "password",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ],
passwordDigestor: "server"
}
)
回答by luckyging3r
I am running a windows subsystem for linux using Ubuntu and was getting this error. Sometimes there's an issue that windows doesn't seem to close mongod
correctly on exit
so you need to Ctrl+Shift+Esc
into task manager and close it manually.
我正在使用 Ubuntu 为 linux 运行 Windows 子系统,但出现此错误。有时会出现窗口似乎无法mongod
正确关闭的问题,exit
因此您需要Ctrl+Shift+Esc
进入任务管理器并手动关闭它。
Actually, whenever mongo seems to be doing anything unusual this seems to be the problem.
实际上,每当 mongo 似乎在做任何不寻常的事情时,这似乎就是问题所在。
Then run mongod
. In another terminal try adding your user again.
然后运行mongod
。在另一个终端尝试再次添加您的用户。
Hope that helps someone.
希望能帮助某人。
回答by khemlal sinha
use "database name"
使用“数据库名称”
db.createUser(
{
user: "username",
pwd: "password",
roles: [ { role: "dbOwner", db: "database name" } ],
mechanisms:[
"SCRAM-SHA-1"
]
}
)
db.createUser( { 用户: "用户名", 密码: "密码", 角色: [ { 角色: "dbOwner", db: "数据库名称" } ], 机制:[
"SCRAM-SHA-1" ] } )