mongoVUE 报 MongoAuthenticationException

刚刚安装完mongo db 并且让这个mongo db安装成系统服务,然后给启动啦,以为自己这就可以像MySQL那样;安装好之后,配合可视化工具Navicat for MySQL简单的就跑起来了,
但是呢,并不是这个样子。出bug啦,我暂且记录一下,正在找解决之法。

Unable to fetch Collection stats
Invalid credentials for database 'lxkdb'.
Type: MongoDB.Driver.MongoAuthenticationException
Stack:    在 MongoDB.Driver.Internal.MongoConnection.Authenticate(String databaseName, MongoCredentials credentials)
   在 MongoDB.Driver.Internal.MongoConnection.CheckAuthentication(MongoDatabase database)
   在 MongoDB.Driver.MongoServerInstance.AcquireConnection(MongoDatabase database)
   在 MongoDB.Driver.MongoServer.AcquireConnection(MongoDatabase database, Boolean slaveOk)
   在 MongoDB.Driver.MongoCursorEnumerator`1.AcquireConnection()
   在 MongoDB.Driver.MongoCursorEnumerator`1.GetFirst()
   在 MongoDB.Driver.MongoCursorEnumerator`1.MoveNext()
   在 MongoDB.Driver.MongoDatabase.GetCollectionNames()
   在 MangoUI.MCollections.GetAll(String db)
   在 MangoUI.MCollections.GetIV(String db)
   在 MangoUI.ComDBOverview.RenderMe()
Command 'authenticate' failed: auth failed (response: { "ok" : 0.0, "errmsg" : "auth failed", "code" : 18, "codeName" : "AuthenticationFailed" })
Type: MongoDB.Driver.MongoCommandException
Stack:    在 MongoDB.Driver.Internal.MongoConnection.RunCommand(String collectionName, QueryFlags queryFlags, CommandDocument command)
   在 MongoDB.Driver.Internal.MongoConnection.Authenticate(String databaseName, MongoCredentials credentials)
Inputs:: 
Command:  authenticate
Ok:       False
ErrorMsg: auth failed
Request:  { "authenticate" : 1, "user" : "root", "nonce" : "e223b8165fde3c14", "key" : "59735f1ed37becab745a07df94c1512b" }
Response: { "ok" : 0.0, "errmsg" : "auth failed", "code" : 18, "codeName" : "AuthenticationFailed" }

这个bug是这么出现的:

启动完MongoDB服务后,cmd命令下进入bin目录下(即MongoDB的安装目录的bin下),执行mongo.exe;进入到mongo的命令行模式。
 

命令:use admin  
注释:MongoDB安装好以后由默认的admin表和local表;其中admin存放的是用户信息

命令:db.createUser({ user: "root",pwd: "root",customData:{name:"root"},roles:[{ role: "userAdminAnyDatabase",db: "admin" }]})
注释:创建一个用户名和密码为root的管理员

创建完后登陆
db.auth('root','root')
show collections


1、切换/创建数据库
use yourDB;  当创建一个集合(table)的时候会自动创建当前数据库,这我看完就直接整个use lxkdb 然后接着就在这数据库里面执行下面那行命令。
2、添加
db.users.save({name: 'zhangsan', age: 25, sex: true});
添加的数据的数据列,没有固定,根据添加的数据为准


如上,我就认为,现在数据库有了,账号密码也有了,那么我是不是可以直接在可视化客户端登录呢,然后我本地有mongoVUE这工具,然后就如下整起来。

奥,数据库刚刚是有个默认的数据库叫test,账号密码都是test,我就测试的连了一下。

测试连接是OK的啦。


然后就出现异常啦。


然后我又现场又测试了下,又有如下的bug图,


就是刚刚注册的root用户测试连接是OK的,但是当打开的时候,就bug啦。


Error encountered
Invalid credentials for database 'admin'.
Type: MongoDB.Driver.MongoAuthenticationException
Stack:    在 MangoUI.ComServerView.RefreshCurrentOps(MMongo mo, TimeSpan& data, TimeSpan& gui, Boolean throwEx)
   在 MangoUI.ComServerView.RenderMe()
Command 'authenticate' failed: auth failed (response: { "ok" : 0.0, "errmsg" : "auth failed", "code" : 18, "codeName" : "AuthenticationFailed" })
Type: MongoDB.Driver.MongoCommandException
Stack:    在 MongoDB.Driver.Internal.MongoConnection.RunCommand(String collectionName, QueryFlags queryFlags, CommandDocument command)
   在 MongoDB.Driver.Internal.MongoConnection.Authenticate(String databaseName, MongoCredentials credentials)
Inputs:: 
Command:  authenticate
Ok:       False
ErrorMsg: auth failed
Request:  { "authenticate" : 1, "user" : "root", "nonce" : "48caca9848431a7b", "key" : "bcb3d50b9ead4d515cf04a01619be5ea" }
Response: { "ok" : 0.0, "errmsg" : "auth failed", "code" : 18, "codeName" : "AuthenticationFailed" }

看异常的内容,应该是权限认证问题惹的祸。

恕在下愚笨,搞了很久也没整明白为什么这个mongoVUE就是报错,我看我们项目用的mongo是2.2.2

我这个用的是3.4.而,mongoVUE的版本是1.5.3.

我是真无奈啦。



最后的测试结果是这样的:

错的不是这个程序,或者步骤。是这个mongoVUE的版本太低了

所以。你换个可视化工具。就可以了。


这个工具的网址,算是个开源的项目吧。
http://blog.robomongo.org/robomongo-0-9-0-final/
我下载的到某度云盘的分享
链接:http://pan.baidu.com/s/1bp8ALDP 密码:iaie


下面是安装完之后,正确的执行步骤,创建管理账户用户和普通用户的步骤,

Create amdin user in mongodb shell and exit.创建管理账户,然后退出。

use admin
db.createUser(
  {
    user: "admin",
    pwd: "password",
    roles: [ { role: "root", db: "admin" } ]
  }
);
exit;

上面的重点就是那个role,选的root,你要是选其他的,估计就不好确定安全不啦。


Shell back into mongodb with the above admin user,用上面创建的管理账户登录,

mongo --port 27017 -u admin -p password --authenticationDatabase admin
Create user for a database called test, with read and write access to test创建个普通的账户,权限是可读可写。
use test
db.createUser(
    {
      user: "tester",
      pwd: "password",
      roles: [
         { role: "readWrite", db: "test" }
      ]
    }
);
Shell into mongodb with the test user,用普通账户登录。
mongo -u tester -p --authenticationDatabase test

估计这么着就OK了。

因为这篇,的错误太多了我就在下一篇,再示范一遍正确的姿势。从头到尾。


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值