Using collect with a [[Cursor.ErrorHandler]]

813 views
Skip to first unread message

William Ross

unread,
Feb 9, 2017, 4:40:31 AM2/9/17
to ReactiveMongo - http://reactivemongo.org
Hello Stephane, list,

I have managed to update my old Play application to use 0.12 properly and the new future-database approach is very welcome but there is one deprecation message that I can't get rid of. Would you mind having a look and telling me what I've missed?

In ordinary retrieval code like this:

database.flatMap { (db: DefaultDB)
  val collection
: BSONCollection = db.collection(collection_name)
  val futureNotificationList
= collection.find(query).sort(sort).cursor[Notice]().collect[List]()
  futureNotificationList
.map { (notifications: List[Notice]) =>
   
Ok(Json.toJson(notifications)).withHeaders("Access-Control-Allow-Origin" -> "*")
 
}
}

I get the new warning

Symbol "collect" is deprecated. Use `collect` with an [[Cursor.ErrorHandler]]

The find documentation still uses this deprecated form and I am having trouble passing an ErrorHandler. The code comments suggest a signature like this:

val futureNotificationList = cursor.collect[List](100, Cursor.FailOnError())

But that doesn't work at all. I must be missing a scala idiom. Any advice would be greatly appreciated.

thanks,

Will


ps. Play 2.5.10, Scala 2.11.8, ReactiveMongo 0.12.1

luoz...@gmail.com

unread,
Feb 13, 2017, 9:21:48 PM2/13/17
to ReactiveMongo - http://reactivemongo.org
Hello, 

val futureNotificationList = cursor.collect[List](100, Cursor.FailOnError[List[Notice]())

this will work.

William Ross

unread,
Mar 10, 2017, 3:10:07 AM3/10/17
to ReactiveMongo - http://reactivemongo.org
Thank you! And sorry for my late reply; I didn't see this message at the time.

Will
Reply all
Reply to author
Forward
0 new messages