Mongodb ReactiveMongo播放模块:Gridfs文件服务

Mongodb ReactiveMongo播放模块:Gridfs文件服务,mongodb,scala,playframework,gridfs,reactivemongo,Mongodb,Scala,Playframework,Gridfs,Reactivemongo,在play framework上使用ReactiveMongo版本0.11.2编写服务文件的最规范的方法是什么?在旧版本中,我可以通过以下控制器功能来实现 def img(id: String) = Action.async { val file = gridFS.find(BSONDocument("_id" -> BSONObjectID(id))) serve(gridFS, file,dispositionMode = "inline") } 当前的Mon

在play framework上使用ReactiveMongo版本0.11.2编写服务文件的最规范的方法是什么?在旧版本中,我可以通过以下控制器功能来实现

  def img(id: String) = Action.async {
    val file = gridFS.find(BSONDocument("_id" -> BSONObjectID(id)))
    serve(gridFS, file,dispositionMode = "inline")
  }
当前的MongoController GridFS使用的Json序列化程序/反序列化程序对我来说不直接起作用。我想写一些像这样的东西

class Admin @Inject() (val reactiveMongoApi: ReactiveMongoApi) extends Controller with MongoController with ReactiveMongoComponents {
...
  def img(id: String) = Action.async {
       val file = reactiveMongoApi.gridFS.find(Json.obj("_id" -> Json.obj( "$oid" -> id) 
       serve(reactiveMongoApi.gridFS, file)
  }

} 
但它不会编译,当然会在
gridFS.find
行上出错

No Json deserializer found for type T. Try to implement an implicit Reads or Format for this type.

如果我开始写(实际上是从ReactiveMongo开始写)反序列化和序列化到ReadFile的所有隐式代码,它就可以工作了——但是有没有更优雅的方法呢

请看一下。此应用程序使用abit trickies版本的gridfs结构。他们使用自生成的_id作为字符串,而不是ObjectID。这不是技巧,而是选择。