0

I'm starting a project using play 2.2.3 and play-reactivemongo 0.10.2 (which recursively use reactivemongo 0.10.0).

I've read the documentation of both reacticemongo and play-reactivemongo along with a few projet I found on github but I can't figure out how to manage mongo's id in the cleanest way.

Because I'm lazy I decided to use automatic generation of json reader and writer (as shown in https://github.com/ReactiveMongo/Play-ReactiveMongo)

package models

case class User(
  age: Int,
  firstName: String,
  lastName: String,
  feeds: List[Feed])

case class Feed(
  name: String,
  url: String)

object JsonFormats {
  import play.api.libs.json.Json
  import play.api.data._
  import play.api.data.Forms._

  // Generates Writes and Reads for Feed and User thanks to Json Macros
  implicit val feedFormat = Json.format[Feed]
  implicit val userFormat = Json.format[User]
}

And in the same document follows a nice example of how to insert and find documents in a collection. But it does not say a thing about updating.

How do you deal with "_id" when you have to update documents ?

I was asked for an example. Here is one https://github.com/manuelleduc/bookmarks/tree/stackoverflow-example-1 I have a runtime exception when I make a call to /bookmarks route. [RuntimeException: JsError(List((/_id,List(ValidationError(error.expected.jsstring,WrappedArray()))), (/tags,List(ValidationError(error.path.missing,WrappedArray())))))]

Manuel Leduc
  • 1,849
  • 3
  • 23
  • 39
  • Hi Manuel, have you solved your problem? I ran into same issue with reactive mongo findAndUpdate and can't find much useful info online. – Ryan Li Jul 10 '16 at 12:47

1 Answers1

0

Why not just put id or _id field in your case class?

Andrey Neverov
  • 2,135
  • 1
  • 12
  • 21
  • I tried it but it did not went well with reader/writer generation and automatic type conversion from BSONDocument to model objects – Manuel Leduc May 21 '14 at 19:53
  • Interesting, could you please tell more about the problems you encountered? – Andrey Neverov May 21 '14 at 20:59
  • This is an example of problems I have with '_id' https://github.com/manuelleduc/bookmarks/tree/stackoverflow-example-1 I have a runtime exception when I make a call to /bookmarks route. – Manuel Leduc May 22 '14 at 11:25