简体   繁体   English

使用Java的3.0.0驱动程序连接到MongoDB 2.6.3(Eclipse)

[英]Connection to MongoDB 2.6.3 using 3.0.0 driver from Java (eclipse)

My simple program to connect to mongodb 2.6.3 using 3.0.0 driver fails with "Command failed with error 59: 'no such cmd: saslStart' on server ...." 我使用3.0.0驱动程序连接到mongodb 2.6.3的简单程序失败,并显示“命令失败,错误59:服务器上没有这样的cmd:saslStart”。

Any insight is much appreciated. 非常感谢任何见解。

    public static void main(String[] args) {
    MongoCredential credential = MongoCredential.createCredential(MY_TEST_DATABASE_USER, MY_TEST_DATABASE, MY_TEST_DATABASE_PWD);
    // MongoCredential credential = MongoCredential.createScramSha1Credential(MY_TEST_DATABASE_USER, MY_TEST_DATABASE, MY_TEST_DATABASE_PWD); // this failed as well
    try (MongoClient mongoClient = new MongoClient(new ServerAddress(DB_SERVER_2_6_3, DB_PORT), Arrays.asList(credential))) {

        MongoDatabase mdb = mongoClient.getDatabase(MY_TEST_DATABASE);

        MongoCollection<Document> coll = mdb.getCollection(MY_TEST_COLLECTION);

        if (coll != null) {
            System.out.println(coll.find().first());
        }
    }
}

Figured out by trial and error. 通过反复试验弄清楚。 (disappointed with mongo online support/docs on this issue) Used "admin" database when creating credentials. (对此问题,mongo在线支持/文档​​感到失望)在创建凭据时使用了“ admin”数据库。 Figured this out by looking at the connection settings in my Robomongo client. 通过查看Robomongo客户端中的连接设置可以解决此问题。

MongoCredential credential = MongoCredential.createCredential(MY_TEST_DATABASE_USER, "admin", MY_TEST_DATABASE_PWD);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用mongodb java driver 3.0.0从Secondary获取配置文件状态? - How to get profile status from Secondary using mongodb java driver 3.0.0? MongoDb 数据库连接使用 java 和 3.0.0 版本的身份验证 - MongoDb database connection using java and authentication with 3.0.0 version Windows上使用JDK1.6.45的MongoDB 3.0.0 / 2/3 Java驱动程序Kerberos身份验证 - MongoDB 3.0.0/2/3 Java Driver Kerberos Authentication on Windows using JDK1.6.45 使用Java + Eclipse的MongoDB拒绝连接 - MongoDB Refusing Connection using Java + Eclipse 如何在 eclipse 中使用 java Mongo 驱动程序 3.12.0 使用 MongoDB 中的多个字段查询文档 - how to query document using multiple fields from MongoDB using java Mongo driver 3.12.0 in eclipse (MongoDB Java驱动程序(3.0.0-rc0))UnknownHostException&Authentication - (MongoDB Java Driver (3.0.0-rc0)) UnknownHostException & Authentication Mongodb java驱动3.12.1中的MongoDB java连接 - MongoDB java connection in Mongodb java driver 3.12.1 如何防止连接池被 mongodb 上的 java 驱动程序关闭? - How to keep the connection pool from closing with a java driver on a mongodb? MongoDB Java Driver什么时候连接? - When does MongoDB Java Driver makes connection? Could not initialize class com.mongodb.connection.MongoQueryAnalyzer using mongodb Java driver - Could not initialize class com.mongodb.connection.MongoQueryAnalyzer using mongodb Java driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM