I've got a problem with MongoDB User Authentication using the Java driver 2.11.1. I added some admin-users (dbAdmins, userAdmins etc.) to the admin database.
As suggested by the MongoDB tutorial, I use only one instance of the MongoClient object: it's implemented as singleton because the MongoClient object is like an connection pool.
If an admin wants to have access to the database, he will make up a new connection to the database with the global MongoClient instance (get one connection from the pool) and call the authentication method of the driver: an example:
MongoClient mongoClient = new MongoClient("ip", "port");
DB adminDB = mongoClient.getDB("admin");
boolean isAuth = adminDB.authenticate("Admin", "Admin1234".toCharArray());
DB anotherAdminDB = mongoClient.getDB("admin");
boolean isAuth2 = anotherAdminDB.authenticate("UserAdmin", "UserAdmin1234".toCharArray());
If I do so, I will get the exception:
java.lang.IllegalStateException: can't authenticate twice on the same database
But each admin user has to authenticate with it's own credentials. Does anyone had this problem already? How could you solve that problem?
If I create a new MongoClient per admin, then there is no exception thrown and all is correct. But then I can't use the connection pooling of Mongo.
Thank you and best regards.