I have some MongoDB Scala Driver questions and hope some may know.
1) I want to use "ClusterSettings" for setting up MongoDB servers ip addresses and also want to use "ClusterSettings" to enable SSL connection to MongoDB. Do you know how to configure them (settings1 and settings2 below) all at once or join the two configurations after you configure them one by one?
val clusterSettings: ClusterSettings = ClusterSettings.builder().hosts(List(new ServerAddress("localhost")).asJava).description("Local Server").build()
val settings1: MongoClientSettings = MongoClientSettings.builder().clusterSettings(clusterSettings).build()
val settings2: MongoClientSettings = MongoClientSettings.builder().sslSettings(SslSettings.builder().enabled(true).build()).streamFactoryFactory(NettyStreamFactoryFactory()).build()
//how can i combine the above two settings?
2) I want to use "SHA1" for credential, but I cannot make the last line of code below to compile. I may miss one JAR library, but which one?
//don't know how to apply the credential, line 25 does not compile
val credential: MongoCredential = MongoCredential.createScramSha1Credential(user, database, password)
val server1 = new ServerAddress("localhost", 27017)
//val mongo = org.mongodb.scala.MongoClient(server1, List(credential)) //cannot compile
Thanks,
Amy
how can i combine the above two settings?
Hi Amy,
It’s been a while since you posted this question, have you found a solution yet ?
You can just combine the two settings into one MongoClientSettings instance. For example:
val clusterSettings: ClusterSettings = ClusterSettings.builder()
.hosts(List(
new ServerAddress("localhost", 27017)
).asJava
).build();
val settings1: MongoClientSettings = MongoClientSettings.builder()
.credentialList(List(MongoCredential.createCredential("username", "admin", ("password").toCharArray)).asJava)
.clusterSettings(clusterSettings)
.streamFactoryFactory(NettyStreamFactoryFactory())
.sslSettings(SslSettings.builder().enabled(true).build())
.build();
val mongoClient: MongoClient = MongoClient(settings1);
I may miss one JAR library, but which one?
If you’re utilising the current latest MongoDB Scala Driver v2.1, you should be able to find MongoCredential
class in org.mongodb
namespace.
See also MongoCredential.scala
If you have further question, please provide:
how can i combine the above two settings?
Hi Amy,
It’s been a while since you posted this question, have you found a solution yet ?
You can just combine the two settings into one MongoClientSettings instance. For example:
val clusterSettings: ClusterSettings = ClusterSettings.builder()
.hosts(List(
new ServerAddress("localhost", 27017)
).asJava
).build();
val settings1: MongoClientSettings = MongoClientSettings.builder()
.credentialList(List(MongoCredential.createCredential("username", "admin", ("password").toCharArray)).asJava)
.clusterSettings(clusterSettings)
.streamFactoryFactory(NettyStreamFactoryFactory())
.sslSettings(SslSettings.builder().enabled(true).build())
.build();
val mongoClient: MongoClient = MongoClient(settings1);
I may miss one JAR library, but which one?
If you’re utilising the current latest MongoDB Scala Driver v2.1, you should be able to find MongoCredential
class in org.mongodb
namespace.
See also MongoCredential.scala
If you have further question, please provide:
Regards,
Wan.