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.


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).

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

Use DAO

 import dev.mongocamp.driver.mongodb._

  def restaurantsSize: Long = RestaurantDAO.count()

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