score:4

Accepted answer

reactivemongo is way too clever with a lot of these inner case classes, etc., and every time i've had to use it i've run into weird problems like this. you can force it to compile by providing a type annotation that fixes the scope of the existential:

scala> type famresult =
     |   c.batchcommands.findandmodifycommand.findandmodifyresult forsome {
     |     val c: bsoncollection
     |   }
defined type alias famresult

scala> def remove =
     |   testcoll.flatmap[famresult](_.findandremove(bsondocument("atomicnumber" -> 26)))
remove: scala.concurrent.future[famresult]

unless you don't care about the removal command results, though, this probably isn't ideal. a better approach is to map into the future[<blah blah blah>.findandmodifyresult] inside the flatmap so that you end up with a more useful type:

scala> def remove = testcoll.flatmap(
     |   _.findandremove(bsondocument("atomicnumber" -> 26)).map(_.value)
     | )
remove: scala.concurrent.future[option[reactivemongo.bson.bsondocument]]

you could also just .map(_ => ()) if you actually don't care about the result, .map(_.result[element]) if you want the result decoded, etc.


Related Query

More Query from same tag