[JAVA-2414] Can not catch com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' Created: 21/Dec/16 Updated: 27/Oct/23 Resolved: 28/Dec/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Authentication, Cluster Management |
| Affects Version/s: | 3.4.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Martine [X] | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
MongoDB server version is 3.2. mongo java driver is mongo-java-driver-3.4.0.jar. OS is windows 10. |
||
| Description |
|
I have a test about authenticate by mongo-java-driver-3.4.0.jar as below
If give a error username , passoword or databasename, it will throw the following exception:
How to catch the com.mongodb.MongoSecurityException and do not let it throw to console? I need catch and deal with it in my program. Thanks in advance |
| Comments |
| Comment by Martine [X] [ 29/Dec/16 ] |
|
Hi Jeff, Thanks, |
| Comment by Jeffrey Yemin [ 28/Dec/16 ] |
|
As I've not heard back from you I'm closing this issue. Let us know if you have further questions. |
| Comment by Jeffrey Yemin [ 21/Dec/16 ] |
|
Hi Martine, There is no way to catch MongoSecurityException, as it's not thrown to the application; it's actually being logged by a background thread. Instead, your application can catch MongoTimeoutException, which is thrown due to any failure to successfully connect to the necessary server in the MongoDB cluster. In this example, Mongo.getConnectPoint() will throw a MongoTimeoutException after, by default, 30 seconds, which as you seem to have discovered you can shorten by setting serverSelectionTimeout on MongoClientOptions. |
| Comment by Martine [X] [ 21/Dec/16 ] |
|
I want to upgrade mongo java driver from version 2.13.1 to 3.4, but this issue block me. I spend many time to research and can not get result to resolve it. |