2

Folks,

Is this the most elegant way to get a scala List out of casbah?

trains is a subkey in a doc whose value is an array

I was slightly surprised that I had to do the instanceOf and then the asScala to get a first class scala list

Could I have done anything better or more idiomatically scala?

val mongoconn = MongoConnection("titan"){"traininfo"}{"trains"}
    val result = mongoconn.find()
    println()


    for{
      x<-result.toList
      y<-(x.get("trains").asInstanceOf[BasicDBList]).asScala

    }
    {
      println(y);
    }
phatmanace
  • 4,671
  • 3
  • 24
  • 29

1 Answers1

2

why not a simple

val collection = MongoConnection("titan")("traininfo")("trains")
collection.find().foreach(x => x.as[MongoDBList]("train").foreach(t => println(t)))
twillouer
  • 1,149
  • 9
  • 14