【发布时间】:2011-06-17 16:06:33
【问题描述】:
我正在尝试使用 JsonObjectField 保存记录(使用 lift-mongo- 在 Play 框架中记录),但在数据库集合中为空。 这是我的代码:
定义类:
class Wish extends MongoRecord[Wish] with MongoId[Wish] {
def meta = Wish
object body extends StringField(this, 1024)
object tags extends MongoListField[Wish, String](this)
object form extends JsonObjectField[Wish, Criterion](this, Criterion) {
def defaultValue = null.asInstanceOf[Criterion]
}
}
object Wish extends Wish with MongoMetaRecord[Wish] {
override def collectionName = "wishes"
}
case class Criterion (key: String, value: String) extends JsonObject[Criterion] {
def meta = Criterion
}
object Criterion extends JsonObjectMeta[Criterion]
我尝试以这种方式保存记录:
Wish.createRecord.body("body").tags(List("tags", "test")).form(new Criterion("From", "Arbat")).save
在 mongodb 集合中,我有类似的东西:
{ "_id" : ObjectId("4dfb6f45e4b0ad4484d3e8c6"), "body" : "body", "tags" : [ "tags", "test" ], "form" : { } }
我做错了什么?
【问题讨论】:
标签: json scala mongodb playframework lift