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 ...."
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. Figured this out by looking at the connection settings in my Robomongo client.
MongoCredential credential = MongoCredential.createCredential(MY_TEST_DATABASE_USER, "admin", MY_TEST_DATABASE_PWD);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.