Mechanisms to connect to a MongoDB database (scala mongo driver implementation)
To utilise this library add this to your sbt build file
"dev.cjww.libs" % "mongo-connector_2.13" % "x.x.x"
Major Version | Scala Version | Mongo Version |
---|---|---|
0.x.x | 2.13.x | 4.2+ |
1.x.x | 2.13.x | 4.2+ |
Configuration for uri, database and collection is derived from the database repositories package structure.
package.structure {
RepositoryClass {
uri = ""
database = ""
collection = ""
}
}
Flatmapping collection from this trait class will grant access to mongo CRUD operations.
class ExampleDataBaseRepository extends DatabaseRepository {
def findById[T](id: String)(implicit codec: CodecRegistry, ct: ClassTag[T]): Future[Option[T]] = {
collection[T].find[T](equal("_id", id)).first().toFutureOption()
}
}
To ensure each of your repositories indexes are ensured you need to implement RepositoryIndexer. Provide each of your repositories in a sequence. like so
val repoIndexer: RepositoryIndexer = new RepositoryIndexer {
}
repoIndexer.ensureMultipleIndexes[TestModel](testRepository)
This code is open source software licensed under the Apache 2.0 License