Connection to MongoDB using JasperStudio & IReport

Hello,

I'm trying to make connection to MongoDb from JasperStudio without success.
The same identical connection used into IReport works nice.
I'm really confused because I don't know what I would change.

This is the error log but not being a programmers i don't understand almost nothing.  The URI, User, Password are obviously correct.

net.sf.jasperreports.engine.JRException: Error creating MongoDBConnection; Caused by: Cannot test MongoDB connection; Caused by: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='t4h', source='T4H-sample', password=<hidden>, mechanismProperties={}}
    at com.jaspersoft.mongodb.connection.MongoDbConnection.<init>(MongoDbConnection.java:86)
    at com.jaspersoft.mongodb.adapter.MongoDbDataAdapterService.createConnection(MongoDbDataAdapterService.java:70)
    at com.jaspersoft.mongodb.adapter.MongoDbDataAdapterService.test(MongoDbDataAdapterService.java:91)
    at com.jaspersoft.studio.data.wizard.AbstractDataAdapterWizard$3.runOperations(AbstractDataAdapterWizard.java:153)
    at com.jaspersoft.studio.utils.jobs.CheckedRunnableWithProgress$1.run(CheckedRunnableWithProgress.java:50)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: net.sf.jasperreports.engine.JRException: Cannot test MongoDB connection; Caused by: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='t4h', source='T4H-sample', password=<hidden>, mechanismProperties={}}
    at com.jaspersoft.mongodb.connection.MongoDbConnection.test(MongoDbConnection.java:192)
    at com.jaspersoft.mongodb.connection.MongoDbConnection.<init>(MongoDbConnection.java:82)
    ... 5 more
Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='t4h', source='T4H-sample', password=<hidden>, mechanismProperties={}}
    at com.mongodb.internal.connection.SaslAuthenticator.wrapException(SaslAuthenticator.java:173)
    at com.mongodb.internal.connection.SaslAuthenticator.access$300(SaslAuthenticator.java:40)
    at com.mongodb.internal.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:70)
    at com.mongodb.internal.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:47)
    at com.mongodb.internal.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:179)
    at com.mongodb.internal.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:47)
    at com.mongodb.internal.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:152)
    at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:63)
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:127)
    at com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:50)
    at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.open(DefaultConnectionPool.java:390)
    at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:106)
    at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:92)
    at com.mongodb.internal.connection.DefaultServer.getConnection(DefaultServer.java:85)
    at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:115)
    at com.mongodb.client.internal.ClientSessionBinding$SessionBindingConnectionSource.getConnection(ClientSessionBinding.java:111)
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:212)
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:206)
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:116)
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:109)
    at com.mongodb.operation.CommandReadOperation.execute(CommandReadOperation.java:56)
    at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:179)
    at com.mongodb.client.internal.MongoDatabaseImpl.executeCommand(MongoDatabaseImpl.java:184)
    at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:153)
    at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:148)
    at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:138)
    at com.jaspersoft.mongodb.connection.MongoDbConnection.test(MongoDbConnection.java:187)
    ... 6 more
Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server 10.18.192.88:27021. The full response is {"operationTime": {"$timestamp": {"t": 1686039755, "i": 1}}, "ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1686039755, "i": 1}}, "signature": {"hash": {"$binary": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type": "00"}, "keyId": {"$numberLong": "0"}}}}
    at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:179)
    at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:299)
    at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255)
    at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83)
    at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33)
    at com.mongodb.internal.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:130)
    at com.mongodb.internal.connection.SaslAuthenticator.access$100(SaslAuthenticator.java:40)
    at com.mongodb.internal.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:54)
    ... 30 more
 

giovanni.chiozza_1's picture
Joined: Jan 22 2018 - 5:54am
Last seen: 3 months 1 week ago

Thank you for posting to the Jaspersoft Community. Our team of experts has read your question and we are working to get you an answer as quickly as we can. If you have a Jaspersoft Professional Subscription plan, please visit https://support.tibco.com/s/ for direct access to our technical support teams offering guaranteed response times.

arai_4 - 3 months 3 weeks ago

2 Answers:


Hello,

Looking at final caused by error message it seems that, connection is failed because authentication failure with error code 18.

Kindly check connection string configured.

Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server 10.18.192.88:27021. The full response is {"operationTime": {"$timestamp": {"t": 1686039755, "i": 1}}, "ok": 0.0, "errmsg": "Authentication failed.", "code": 18,

We tried to search over internet about this code and found some of the URL where similar error listed.
Kindly have a look at below suggested resolution.

https://howtodoinjava.com/mongodb/command-failed-with-error-18/
https://www.mongodb.com/community/forums/t/mongosecurityexception-except...
https://www.mongodb.com/community/forums/t/mongodb-replicaset-error-auth...

Hope this will help you !!

jphadtar's picture
1532
Joined: Mar 20 2022 - 10:51pm
Last seen: 13 hours 9 min ago

It seems strange because I'm using the identical string of connection that I use successfully with IReport 5.6 and there it works nicely.

Please have a look to the attached image.

Attachments: 
AttachmentSize
Image icon jasper.jpg240.65 KB
giovanni.chiozza_1's picture
Joined: Jan 22 2018 - 5:54am
Last seen: 3 months 1 week ago
Feedback
randomness