Skip to content

MongConfig ​

Database Configuration can be done using MongConfig.

Create MongoConfig with application.conf ​

With default path ​

Default path in application.conf: mongo

json
mongo {
  database = "university"
  host = "localhost"
  port = 270007
  applicationName = "mongo.db.sample"
  userName = "standard_user"
  password = "change_me"
  pool {
    minSize = 5
    maxSize = 100
  }
}

Scala Code Snippet

scala
val config: MongoConfig = MongoConfig.fromPath()

With custom path ​

json
mongo.db.test {
  database = "unit_test"
  host = "localhost"
  port = 270007
  applicationName = "mongo.db.unit.test"
  userName = "unit_test"
  password = "change_me"
}

Scala Code Snippet

scala
val customConfig: MongoConfig = MongoConfig.fromPath("mongodb.db.prod")

Create MongoConfig with custom ClientSettings ​

scala
val config = MongoConfig("my_database", customClientSettings = Some(myClientSettings))

MongoConfig Options ​

MongoConfig holds all the necessary Data for creating a MongoClient.

It is used for DatabaseProvider creation.

KeyDescriptionDefault value
databasedefault database to use
host127.0.0.1
port27017
applicationNamemongocamp-app
userNameused for Authentification
passwordused for Authentification
poolOptionsMongoPoolOptions()
compressorsList: zlib, snappy, zstdList.empty
customClientSettingsNone
additionalServerAddressesList.empty
serverSelectionTimeoutMShow long the driver waits for a suitable server (e.g. a new primary during replica set failover) before giving up. Accepts Typesafe Config duration syntax (30s, "1 minute", or a plain number treated as milliseconds)30000 ms

MongoConfig Pool Options ​

KeyDefault value
maxConnectionIdleTime60
maxSize50
minSize0
DefaultMaintenanceInitialDelay0

Released under the Apache License 2.0.