我正在使用带有 play-reactivemongo 和 casbah 的 Play2 框架。我有以下代码:
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 并且我得到一个错误 Ok(geoEvents)
Cannot write an instance of Option[mongoColl.T] to HTTP response. Try to define a Writeable[Option[mongoColl.T]]
问:如何将 val geoEvents 转换为 json 以进行响应?
谢谢