2014-09-30 93 views
1

我有一個存儲在MongoDB中的二維數組的案例類, ,因爲薩拉特不支持數組我試圖寫我自己的轉換器。Casbah多維數組 - 檢索數據庫

case class Matrix(id: String, matr: Array[Array[Int]]) 

implicit def toDBObject(m: Matrix) = MongoDBObject(
    "id" -> m.id, 
    "matr" -> s.matr 
) 

implicit def toMatr(in: MongoDBObject) = Matrix(
    in.as[String]("id"), 
    in.as[Array[Array[Int]]]("matr") // This does not work 
) 

toDBObject工作正常,但toMatr不工作。我該如何做這項工作?

回答

1

我設法得到它與產量和兩個工作循環:

for (e <- in.as[MongoDBList]("matr").toArray) 
    yield for (x <- e.asInstanceOf[BasicDBList].toArray) yield x.asInstanceOf[Int] 

這種轉換2D MongoDBList到二維數組斯卡拉