play2 mongodb MongoCursor到Json

时间:2015-03-03 14:01:18

标签: mongodb scala playframework-2.3 casbah play-reactivemongo

我正在使用Play2框架与play-reactivemongo和casbah。我有以下代码:

def geofence(lat:Float, lon:Float, rad:Float) = Action { request =>
  val mongoColl = MongoConnection()("db")("geofence")
  mongoColl.ensureIndex(MongoDBObject("loc" -> "2dsphere"))

  val geo = MongoDBObject(
   "loc" -> MongoDBObject(
    "$nearSphere" -> MongoDBObject(
     "type" -> "Point",
      "coordinates" -> MongoDBList( 52.431929,
       13.506188)
    ),
   "$maxDistance" -> 10000 ))

  val geoEvents=mongoColl.find(geo)
  println(geoEvents)

  Ok(geoEvents)
}

我向服务器发送http请求。取决于参数我想在我的数据库中找到所有数据。问题出在mongoColl.find我只得到了MongoCursor,我得到了错误(geoEvents)

Cannot write an instance of Option[mongoColl.T] to HTTP response. Try to define a Writeable[Option[mongoColl.T]]

:如何将val geoEvents转换为json以进行响应?

由于

0 个答案:

没有答案