BsonDao operates on reactivemongo.api.collections.default.BSONCollection. You will need to define a DAO for each of your models(case classes).
Below is a sample model.
case class Person(
_id: BSONObjectID = BSONObjectID.generate,
name: String,
surname: String,
age: Int)
Now let's define a BsonDao for this model.
object PersonDao extends BsonDao[Person] {
def db: DB = ???
val collectionName: String = "persons"
}
db
and collectionName
are the only required members of BsonDao.
def findOne(selector: BSONDocument): Future[Option[T]]
def findById(id: BSONValue): Future[Option[T]]
def insert(document: T): Future[LastError]
def insert(documents: TraversableOnce[T]): Future[Int]
def updateById(id: BSONValue,
update: BSONDocument,
writeConcern: GetLastError = GetLastError(),
upsert: Boolean = false,
multi: Boolean = false): Future[LastError]
def save(document: T, writeConcern: GetLastError = GetLastError())
def count(selector: BSONDocument = BSONDocument.empty): Future[Int]
def foreach(selector: BSONDocument = BSONDocument.empty,
sort: BSONDocument = BSONDocument(idField -> 1))(f: (T) => Unit): Future[Unit]
def fold[A](selector: BSONDocument = BSONDocument.empty,
sort: BSONDocument = BSONDocument(idField -> 1),
state: A)(f: (A, T) => A): Future[A]
def drop(): Future[Boolean]
def dropSync(timeout: Duration = 10 seconds): Boolean