Skip to content

DatabaseProvider

DatabaseProvider is the central repository for MongoClient, databases, collections and DocumentDAO`s.

DatabaseProvider gives access to

  • MongoClient
  • MongoDatabase
  • MongoCollection

DocumentDAO

From an DocumentDAO you can perform DocumentDAO initialization and caching. On this DAO you can perform CRUD operations.

scala
val dao         = provider.dao("people")
val count: Long = dao.count().result()

Transactions

withTransaction executes a block inside a client session with automatic commit and rollback:

scala
provider.withTransaction { session =>
  PersonDAO.insertOne(alice, session).result()
  PersonDAO.updateOne(filter, update, session).result()
}

See Transactions for full API details.

Collection Creation

Capped Collections

scala
provider.createCappedCollection("audit_log", maxSizeBytes = 10 * 1024 * 1024).result()

Time-Series Collections

scala
provider.createTimeSeriesCollection(
  collectionName = "sensor_readings",
  timeField      = "timestamp"
).result()

See Collection Management for full API details.

Registries

DANGER

Registries are no longer supported for automatic case class conversion. For scala 3 support we changed from mongodb driver conversion to circe conversion.

Released under the Apache License 2.0.