Skip to content

MongoDAO

Info

MongoDAO is the core of this framework. The DAO Pattern simplifies database usage.

The MongoDAO object holds a reference to a MongoCollection and adds functions for easy collection handling.

Features

Usage

A DatabaseProvider is needed.

scala

private val registry = fromProviders(classOf[Restaurant])

val provider = DatabaseProvider("database", registry)

Create DAO

A Type Parameter is used for automatic Document to Class conversion (case classes needs to be registered).

scala
  object RestaurantDAO extends MongoDAO[Restaurant](provider, "restaurants")

Use DAO

scala
 import dev.mongocamp.driver.mongodb._

  def restaurantsSize: Long = RestaurantDAO.count()

  def findAllRestaurants:List[Restaurant] = RestaurantDAO.find()

Released under the Apache License 2.0.