case class TypeTestJsonObject(
intField: Int,
stringField: String
) extends JsonObject[TypeTestJsonObject]
{
def meta = TypeTestJsonObject
}
object TypeTestJsonObject extends JsonObjectMeta[TypeTestJsonObject]
class ListTestRecord private () extends MongoRecord[ListTestRecord] with UUIDPk[ListTestRecord] {
def meta = ListTestRecord
object mandatoryMongoJsonObjectListField extends MongoJsonObjectListField(this, TypeTestJsonObject)
}
object ListTestRecord extends ListTestRecord with MongoMetaRecord[ListTestRecord]
To add an item to the field:
import net.liftweb.json._
import net.liftweb.json.JsonDSL._
val rec = ListTestRecord.find(...)
val newObj = TypeTestJsonObject(1, "a")
val qry: JValue = ("_id" -> ....)
val upd: JValue = ("$push" -> ("mandatoryMongoJsonObjectListField" -> newObj.asJObject))
rec.update(qry, upd)
To remove an item:
val upd: JValue = ("$pull" -> ("mandatoryMongoJsonObjectListField" -> newObj.asJObject))
rec.update(qry, upd)
I've been thinking of adding these functions to the ListFields but haven't gotten around to it.
Rogue has a much better way of doing this, btw. If you haven't looked into that, I highly recommend it. Not sure if MongoJsonObjectListField is supported, though.
Tim