我的id
是长的。但是,如果我getAs[String]
,它会盲目地返回Some(0)
而不是无。它检查密钥的存在而不是类型。
scala> collection
res26: com.mongodb.DBObject = { "_id" : { "$oid" : "520f8bf544ae41ec63d02eec"} , "date_about" : "2013-08-17T20:13:00.365Z" , "date_created" : "2013-08-17T20:13:00.365Z" , "date_modified" : "2013-09-07T18:03:20.101Z" , "id" : 0 , "node_type" : "meta-folder" , "parent_id" : 0 , "title" : "my stuff, renamed by ajax, wow" , "version" : 2}
scala> collection.getAs[String]("id")
res27: Option[String] = Some(0)
scala> collection.getAs[Long]("id")
res28: Option[Long] = Some(0) //get-ing this is an java.lang.ClassCastException
scala> collection.getAs[Long]("id").get
res29: Long = 0
这不是意料之外的行为;我应该没有Option[String] = None
吗?我如何得到预期的行为?我sbt-ed“org.mongodb”%%“casbah”%“2.6.2”