Standard practice for spray and casbah connection

3 views
Skip to first unread message

Dinesh Maske

unread,
May 14, 2015, 5:28:56 AM5/14/15
to spray...@googlegroups.com
I am new in Spray.
I am using spray 1.3 with mongoDb database.
For mongodb connection i use Casbah Driver.

Following is my Connection object

import com.mongodb.casbah.{MongoClient, MongoCollection, MongoConnection}
import config.Configuration

object MongoFactory extends Configuration{

private val USERS = "users"

val mongoClient = MongoClient(mongodbHost, mongodbPort)
val db = mongoClient(mongodbName)
val USER_COLLECTION = db(USERS)

}

This object is used for connection to mongodb.

def create(user: User) = {
val doc = UserMongoMap.toBson(user)
MongoFactory.USER_COLLECTION.insert(doc)
}

This is my repository class method

Is this implementation is correct? OR i need changes according to spray for better performance?
Reply all
Reply to author
Forward
0 new messages