Two things to try:
List more than one server in the replica set in the URL. Example: jdbc:mongo://IP1:27017,IP2:27017/dbname?replicaSet=dbname&readPreference=secondaryPreferred&connectWithNoPrimary=true&slaveOk=true
Use the alternate JDBC URL syntax jdbc:mongodb://[user:pw]@host1,host2/database?replicaSet=dbname&readPreference=secondaryPreferred&connectWithNoPrimary=true&slaveOk=true
The Mongo documentation specifies the second URL format where the first URL format is from the JDBC driver itself.
... View more