Skip to content

Instantly share code, notes, and snippets.

@agemooij
Created December 30, 2010 12:13
Show Gist options
  • Save agemooij/759718 to your computer and use it in GitHub Desktop.
Save agemooij/759718 to your computer and use it in GitHub Desktop.
A base trait for creating and managing a mongoDB connection/collection
package com.agemooij.mongodb
import com.mongodb.casbah.Imports._
trait MongoRepository {
protected val host = "localhost"
protected val port = 27017
protected val databaseName = "agemooij"
protected val collectionName: String
protected def afterCollectionInitialized(collection: MongoCollection) {}
protected lazy val connection = MongoConnection(host, port)
protected lazy val database = connection(databaseName)
protected lazy val collection = {
val col = database(collectionName)
afterCollectionInitialized(col)
col
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment