mongodb - Getting value map is not a member of Object when doing getOrElse with Future in my Play2 app -


i'm trying comprehension when calling mongo instance reactivemongo. method should check if result returned, if not return future(notfound). i'm getting error don't understand.

[info] compiling 8 scala sources , 1 java source /users/projects/reco_play/parser/target/scala-2.10/classes... [error] /users/projects/reco_play/parser/app/controllers/application.scala:94: value map not member of object [error]           }.getorelse(future(notfound)) [error]                      ^ [error] 1 error found [error] (compile:compile) compilation failed 

imports:

import play.api.mvc._ import play.api.play.current import play.api.logger import play.modules.reactivemongo.{reactivemongoplugin, mongocontroller} import models.{company} import reactivemongo.api.collections.default.bsoncollection import reactivemongo.bson.{bsonobjectid, bsondocument} import org.joda.time.datetime import scala.concurrent.{future, executioncontext} 

method:

def showeditform(id: string) = action {     implicit request =>       implicit val reader = company.companyreader       async {         val objectid = new bsonobjectid(id)         val cursor = collection.find(bsondocument("_id" -> objectid)).cursor[company]          {           maybecompany <- cursor.headoption           result <- maybecompany.map { company =>               ok(views.html.editform(some(id), company.form.fill(company)))           }.getorelse(future(notfound))         } yield result       }   } 

okay, looked @ example more , right it's different issue answered with. first, try changing for-comp this:

    {       maybecompany <- cursor.headoption     } yield {        maybecompany.map{company =>          ok(views.html.editform(some(id), company.form.fill(company)))       }.getorelse(notfound)     } 

the issue seeing had mixing types in for-comp. started for-comp future , tried switch option next step. unfortunate feature of for-comps in whatever type start on first line same type have continue throughout comprehension. because can not flatmap future[t] option[t] happen in for-comp had. way follows:

    {       maybecompany <- cursor.headoption       result <- promise.successful(maybecompany.map { company =>           ok(views.html.editform(some(id), company.form.fill(company)))       }).future     } yield result.getorelse(notfound) 

in approach, on second step of for-comp, i'm wrapping option result in completed future, correct type use continuing comprehension.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -