* @param password the (optional) password to use.
* @throws MongoException in case the connection or authentication failed.
*/
private void connectToDB(MongoDB mongoDB, String userName, String password) throws MongoException {
if (!mongoDB.connect(userName, password)) {
throw new MongoException("Failed to connect to MongoDB! Authentication failed!");
}
DBCollection collection = mongoDB.getCollection();
if (collection == null) {
throw new MongoException("Failed to connect to MongoDB! No collection returned!");
}
collection.ensureIndex(new BasicDBObject(NAME, 1).append("unique", true));
}