Apache-2.0 license Download

reactive-mongo

Mechanisms to connect to a MongoDB database (reactive mongo implementation)

To utilise this library add this to your sbt build file

"com.cjww-dev.libs" % "reactive-mongo_2.11" % "x.x.x" 

About

Configuration

Configuration for uri, database and collection is derived from the database repositories package structure.

    package.structure {
      RepositoryClass {
        uri = ""
        database = ""
        collection = ""
      }
    }

com.cjwwdev.mongo.DatabaseRepository

Flatmapping collection from this trait class will grant access to mongo CRUD operations.

    class ExampleDataBaseRepository extends DatabaseRepository {
      def findById(id: String): Option[JsObject] = {
        collection flatMap {
          _.find(BSONDocument("_id" -> id)).one[JsObject]
        }
      }
    }

com.cjwwdev.mongo.indexes.RepositoryIndexer

To ensure each of your repositories indexes are ensured you need to implement RepositoryIndexer. Provide each of your repositories in a sequence. like so

    class ExampleRepoIndexer extends RepositoryIndexer {
      override val repositories: Seq[DatabaseRepository] = Seq(TestRepo1, TestRepo2)
      
      runIndexing
    }

License

This code is open source software licensed under the Apache 2.0 License