MongoDB : Failed to execute "listdatabases" command

在admin库里面这样创建用户:

db.createUser({user:"demo1user",pwd:"demo1",roles:[{role:"dbOwner",db:"demo1"}]})

查询用户的信息发现:

{ "_id" : "admin.demo1user", "userId" : UUID("72c53c6b-ebb0-4619-b958-fa53c9224802"), "user" : "demo1user", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "fuAy0vmJN0FD1cB/FrPTnw==", "storedKey" : "wyyVMsWsmLJ8c2sEJ0hMvTeKghE=", "serverKey" : "AeD7TFGIwI2eauozWDg+07+OJ9E=" }, "SCRAM-SHA-256" : { "iterationCount" : 15000, "salt" : "yhIJVNUUhwGns9xvp0BuTQoLa8GM7AOVJuKavw==", "storedKey" : "SYSMomAEV+QWQvLNoOnL+rcWbj95n0LFY5RHS9A2Ia0=", "serverKey" : "eagFJaH82r8NzrEGv3jjqyZubqnx5Gjdi9bJebYxQO8=" } }, "roles" : [ { "role" : "dbOwner", "db" : "demo1" } ] }

 

那么连接的时候就会出现

Failed to execute "listdatabases" command​

 

正确姿势:

先执行:

use demo1

然后再

db.createUser({user:"demo1user",pwd:"demo1",roles:[{role:"dbOwner",db:"demo1"}]})

你可能感兴趣的:(数据库,mongoDB,mongodb)