开发者社区> 问答> 正文

mongodb副本集加上权限校验后java客户端连接不上?报错

mongodb副本集,不加权限校验的时候客户端连接是没有问题的,加上权限校验后,就报如下异常:

Caused by: com.mongodb.MongoException$Network: IOException authenticating the connection
    at com.mongodb.DBPort$NativeAuthenticator.authenticate(DBPort.java:661)
    at com.mongodb.DBPort.authenticate(DBPort.java:370)
    at com.mongodb.DBPort.checkAuth(DBPort.java:381)
    at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:299)
    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:279)
    at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:84)
    at com.mongodb.DB.command(DB.java:317)
    at com.mongodb.DB.command(DB.java:296)
    at com.mongodb.DBCollection.getCount(DBCollection.java:1189)
    at com.mongodb.DBCollection.getCount(DBCollection.java:1154)
    at com.mongodb.DBCollection.getCount(DBCollection.java:1138)
    at com.mongodb.DBCollection.getCount(DBCollection.java:1107)
    at com.mongodb.DBCollection.getCount(DBCollection.java:1066)
    at cn.sunline.ltts.base.ftp.TestDemo.test(TestDemo.java:90)
    ... 25 more
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:196)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at org.bson.io.Bits.readFully(Bits.java:48)
    at org.bson.io.Bits.readFully(Bits.java:35)
    at org.bson.io.Bits.readFully(Bits.java:30)
    at com.mongodb.Response.<init>(Response.java:42)
    at com.mongodb.DBPort$1.execute(DBPort.java:141)
    at com.mongodb.DBPort$1.execute(DBPort.java:135)
    at com.mongodb.DBPort.doOperation(DBPort.java:164)
    at com.mongodb.DBPort.call(DBPort.java:135)
    at com.mongodb.DBPort.findOne(DBPort.java:189)
    at com.mongodb.DBPort.runCommand(DBPort.java:197)
    at com.mongodb.DBPort$NativeAuthenticator.authenticate(DBPort.java:653)
    ... 38 more

 

mongodb服务端版本为:mongodb-linux-x86_64-rhel62-3.2.7

java客户端使用的版本为:mongo-java-driver-2.12.1.jar

 

我要上传文件导名为mongodb的库,在这个库中用户都建了,但是就是报错

这是客户端测试代码:

ServerAddress sa = new ServerAddress("172.18.50.113:27017");
            ServerAddress sa1 = new ServerAddress("172.18.50.114:27017");
            
            List<ServerAddress> sends = new ArrayList<ServerAddress>();
            sends.add(sa);
            sends.add(sa1);
            List<MongoCredential> mongoCredentialList = new ArrayList<MongoCredential>();
            mongoCredentialList.add(MongoCredential.createMongoCRCredential("common", "mongodb", "common".toCharArray()));
            DB db = new MongoClient(sends, mongoCredentialList).getDB("mongodb");
            DBCollection collection = db.getCollection("phfund_ds.datas");
            System.out.println(collection.getCount());

 

请问有哪位大虾知道为什么吗?求赐教!

展开
收起
爱吃鱼的程序员 2020-06-08 16:50:20 867 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    Credential的帐密是否对?

    2020-06-08 16:50:34
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载

相关镜像