我花了这么多时间,仍然不明白这里的问题是什么。所以我有一个数据集,看起来像:
{ "_id" : "someId", "employment" : { "data" : [
{ "retrieved" : { "$date" : "2015-03-12T14:39:41.214Z"} , "value" : { "city" : "someSity" , "fromMonth" : 0 , "name" : "someName" , "fromYear" : 2011 , "toMonth" : 0 , "speciality" : "someSpeciality"}},
{ "retrieved" : { "$date" : "2015-03-12T14:39:41.214Z"} , "value" : { "city" : "someSity" , "fromMonth" : 7 , "name" : "someName" , "fromYear" : 2013 , "toMonth" : 7 , "toYear" : 2014 , "speciality" : "someSpeciality"}},
{ "retrieved" : { "$date" : "2015-03-12T14:39:41.214Z"} , "value" : { "city" : "someSity" , "fromMonth" : 10 , "name" : "someName" , "fromYear" : 2010 , "toMonth" : 10 , "toYear" : 2010 , "speciality" : "someSpeciality"}}
{ "retrieved" : { "$date" : "2015-03-12T14:39:41.214Z"} , "value" : { "fromMonth" : 2 , "name" : "someName" , "fromYear" : 2007 , "toMonth" : 2 , "toYear" : 2010 , "speciality" : "someSpeciality"}}
]}}
我还有SalatDAO:
object ProfileDAO extends SalatDAO[Profile, ObjectId](
collection = MongoFactory.getDB("profiles"))
当然还有一堆case class
:
case class Profile(
@Key("_id") id: String,
employment: Option[ListField[Employment]]
case class ListField[T](
data: List[Value[T]])
case class Value[T](
value: Option[T],
retrieved: Option[Instant],
deleted: Option[Instant])
最后是就业类别:
case class Employment(
name: Option[String],
country: Option[String],
city: Option[String],
fromMonth: Option[Int],
toMonth: Option[Int],
fromYear: Option[Int],
toYear: Option[Int],
speciality: Option[String]
)
当我尝试做这样的事情时Byt:
ProfileDAO.findAll().take(20).map(
profile => profile.employment.map(
employment => employment.data.map(
employmentData => employmentData.value.name)))
.foreach(println)
我得到异常:com.mongodb.BasicDBObject cannot be cast to com....Employment
我只有一个想法-DBCollection中的一些数据与Employment类不匹配,但有Option[]evrywhere,所以…
转到它爆炸的地方并打印无法反序列化的文档的_id
值?