I'm attempting to connect Jaspersoft Studio 6.2.0 to a MongoDB database (mongod version: 3.0.7) hosted on MongoLab.
Using the connection URI:
mongodb://ds012345-a0.mongolab.com:12345,ds012345-a1.mongolab.com:12345/mydb?replicaSet=rs-ds012345
I get the following exception when testing the adapter :
net.sf.jasperreports.engine.JRException: com.mongodb.CommandFailureException: { "serverUsed" : "ds012345-a0.mongolab.com:12345" , "ok" : 0.0 , "errmsg" : "auth failed" , "code" : 18}
at com.jaspersoft.mongodb.connection.MongoDbConnection.test(MongoDbConnection.java:162)
at com.jaspersoft.mongodb.adapter.MongoDbDataAdapterService.test(MongoDbDataAdapterService.java:93)
at com.jaspersoft.studio.data.wizard.AbstractDataAdapterWizard$3.runOperations(AbstractDataAdapterWizard.java:162)
at com.jaspersoft.studio.utils.jobs.CheckedRunnableWithProgress$1.run(CheckedRunnableWithProgress.java:59)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.mongodb.CommandFailureException: { "serverUsed" : "ds012345-a0.mongolab.com:12345" , "ok" : 0.0 , "errmsg" : "auth failed" , "code" : 18}
at com.mongodb.CommandResult.getException(CommandResult.java:76)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:131)
at com.mongodb.DBPort$NativeAuthenticator.authenticate(DBPort.java:652)
at com.mongodb.DBPort.authenticate(DBPort.java:364)
at com.mongodb.DBPort.checkAuth(DBPort.java:375)
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:291)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:271)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:84)
at com.mongodb.DB.command(DB.java:317)
at com.mongodb.DB.command(DB.java:296)
at com.mongodb.DB.command(DB.java:371)
at com.mongodb.DB.command(DB.java:243)
at com.mongodb.DB.command(DB.java:397)
at com.jaspersoft.mongodb.connection.MongoDbConnection.test(MongoDbConnection.java:158)
... 4 more
The issue is with the SCRAM-SHA-1 authentication mechanism added in MongoDB version 3.0.
As mentioned in this JasperReports Server issue, the solution is to update the MongoDB Java driver by replacing the file:
Jaspersoft Studio-6.2.0.final\configuration\org.eclipse.osgi\29\0\.cp\lib\mongo-java-driver-2.12.3.jar
with the one found here: https://github.com/mongodb/mongo-java-driver/releases/download/r2.13.2/mongo-java-driver-2.13.2.jar
With the credentials in the URI, the connection succeeds.