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

时间:2015-11-20 21:12:50

标签: java eclipse mongodb

使用3.0.0驱动程序连接到mongodb 2.6.3的简单程序失败了 "命令失败,错误59:'没有这样的cmd:saslStart'在服务器上...."

非常感谢任何见解。

    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());
        }
    }
}

0 个答案:

没有答案