(MongoDB Java Driver (3.0.0-rc0)) UnknownHostException & Authentication -


recently started using new mongodb java driver (3.0.0-rc0). @ moment have 2 problems.

  • the serveraddress class isn't throwing unknownhostexception anymore, used exception determine if connection succeed or not, should use now?

  • the db class became mongodatabase class. when db class wasn't deprecated used authenticate(string username, char[] password) authenticate, need use mongocredential class, how check if authentication succeed or not?

with regards, julian v.d berkmortel

the 3.0 java driver takes position

  • host names aren't in dns
  • unreachable hosts
  • incorrect authentication credentials

are severe application configuration errors require human intervention , therefore surfaced in api indirectly through exceptions thrown in course of normal use of driver.

so in both these cases driver throw mongotimeoutexception method needs connect mongodb server. exception include message indicating root cause of connection failure. instance, following program:

    mongoclient mongoclient = new mongoclient(new serveraddress("unknown-host-name"),                                               mongoclientoptions.builder()                                                                 .serverselectiontimeout(5000)                                                                 .build());     mongoclient.getdatabase("admin").runcommand(new document("ping", 1)); 

will throw exception message:

   timed out after 30000 ms while waiting server matches    readpreferenceserverselector{readpreference=primary}.     client view of cluster state {type=unknown,     servers=[{address=unknown-host-name:27017, type=unknown, state=connecting,     exception={com.mongodb.mongosocketexception: unknown-host-name},     caused {java.net.unknownhostexception: unknown-host-name}}] 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -