I am new to MongoDb. I was trying to retreive data from the db. Here is part of my code:
dbc(TABLENAME).find ( MongoDBObject (UID -> uid)).toList.foreach {s =>
val Rollno = s.getAs[String](ROLL).getOrElse ("?")
Apparently ROLL is set as integer, and I keep on getting the error java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String Is there an easy solution to get it?
How about getting it as an integer and then using toString?
dbc(TABLENAME).find ( MongoDBObject (UID -> uid)).toList.foreach {s =>
val Rollno = s.getAs[Int](ROLL).map(_.toString).getOrElse("?")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.