我正在使用play 2.2.3和play-reactivemongo 0.10.2 (递归地使用reactivemongo 0.10.0)启动一个项目。
我已经阅读了reacticemongo和play-reactivemongo的文档,以及我在github上找到的一些项目,但我想不出如何以最干净的方式管理mongo的id。
因为我很懒,所以我决定使用json读取器和写入器的自动生成(如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]
}在同一文档中,遵循了如何在集合中插入和查找文档的一个很好的示例。但它并没有说明什么是更新。
当您必须更新文档时,如何处理"_id“?
我被要求举一个例子。下面是一个https://github.com/manuelleduc/bookmarks/tree/stackoverflow-example-1,当我调用/bookmarks路由时,它有一个运行时异常。[RuntimeException: JsError(List((/_id,List(ValidationError(error.expected.jsstring,WrappedArray()))), (/tags,List(ValidationError(error.path.missing,WrappedArray())))))]
发布于 2014-05-20 17:42:38
为什么不在你的case类中加入id或者_id字段呢?
https://stackoverflow.com/questions/23742483
复制相似问题