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

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -