MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Impossibile autenticare l'utente in MongoDB 3.0.2 utilizzando la connessione java

Un po' di ricerca e ho scoperto che Mongo 3 non ama la risposta alle sfide e preferisce "MongoCredential.createScramSha1Credential '

List<ServerAddress> seeds = new ArrayList<ServerAddress>();
seeds.add( new ServerAddress( "remoteServer" ));
List<MongoCredential> credentials = new ArrayList<MongoCredential>();
credentials.add(
    MongoCredential.createScramSha1Credential(
        "username",
        "adminDatabase",
        "password".toCharArray()
    )
);
MongoClient mongoClient = new MongoClient( seeds, credentials );
MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongoClient, "applicationDatabase");
mongoTemplate = new MongoTemplate(mongoDbFactory);