0
我想从java访问mongodb使用mongo java驱动3.4。我写下面的代码访问MongoDB,即使我连接时输入了错误的凭据,我仍然可以访问我的数据库。Mongo的java驱动认证不能正常工作
MongoCredential credential = MongoCredential.createScramSha1Credential("rupesh_user", "rupesh_db",
"admin123".toCharArray());
MongoClient mongoClient= new MongoClient(new ServerAddress("localhost", 27017), Arrays.asList(credential));
当我试图从ubuntu的终端访问mongo数据库。它要求认证。
> use rupesh_db
switched to db rupesh_db
> show collections
2017-08-03T13:07:52.970+0530 E QUERY [thread1] Error: listCollections failed: {
"ok" : 0,
"errmsg" : "not authorized on rupesh_db to execute command { listCollections: 1.0, filter: {} }",
"code" : 13,
"codeName" : "Unauthorized"
} :
感谢#4J41请帮我解决这个问题 –
看起来你已经创建的证书,但确实是用户具有“ readWrite'权限角色的数据库? –
#Rahul Kumar是的,该用户具有ReadWrite权限。问题来自终端我无法访问相同的数据库没有身份验证。但是使用mongo java驱动程序不需要认证。我完全困惑。请帮我 –