Created
December 30, 2010 12:13
-
-
Save agemooij/759718 to your computer and use it in GitHub Desktop.
A base trait for creating and managing a mongoDB connection/collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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