path("test" /"db" /"find") {
get{
complete {
// Error
collection.find.toList.toBlocking
"Done"
}
}
}~
Hi,
It depends on what you are trying to achieve. If you are just wanting to return the results from a collection find, you don’t have to create a case class. Just make sure that the value in complete() is marshallable.
As an example using Casbah to serialise the result from collection.find():
import com.mongodb.casbah.Imports._
path("test") {
get{
val documents = collection.find().toList
complete(com.mongodb.util.JSON.serialize(documents))
}
}
Or if you are interested only in a particular field of a document you could do:
path("test") {
get{
val document = collection.findOne.get
complete(com.mongodb.util.JSON.serialize(document("fieldName")))
}
}
Regards,
Wan.