How to put datas from MongoDB into an object with Casbah and Scala -
i want put in "user" class datas mongodb. find()
method doesn't return type want.
i have piece of code, don't know how can use :
def finduser(username: string) : option[user] = { var user:option[user] = none val usertofind = mongodbobject("username" -> username) users.findone(usertofind).foreach { x => user = some(new user(x("username").tostring,x("password").tostring,x("firstname").tostring, x("lastname").tostring, true,2)) } user }
how use result put object parameters ?
this object user :
class user ( val username : string, var password : string, var firstname : string, var lastname : string, var isactivated : boolean, val tenantid : int ) {}
for example this:
def finduser(username: string): option[user] = { val result = mongocolluser.findone(mongodbobject("username"->username)); result.map { user => touser(user) } } def touser(dbobject:dbobject) : user = { user(dbobject.as[string]("username"),dbobject.as[string]("password"),dbobject.as[string]("firstname"),dbobject.as[string]("lastname"),dbobject.as[boolean]("isactivated"),dbobject.as[int]("tenantid")) } case class user ( val username : string, var password : string, var firstname : string, var lastname : string, var isactivated : boolean, val tenantid : int )
Comments
Post a Comment