Skip to content

Instantly share code, notes, and snippets.

@eltimn
Created November 5, 2014 10:53
Show Gist options
  • Save eltimn/c5a5827dc589d20d3681 to your computer and use it in GitHub Desktop.
Save eltimn/c5a5827dc589d20d3681 to your computer and use it in GitHub Desktop.
Lift Mongo Enum List Field Example
object enumFieldArray extends MongoListField[SomeEntity, Enum](this) {
val enum = SomeEnum
override def asDBObject: DBObject = {
val dbl = new BasicDBList
value.foreach { f => dbl.add(f.toString) }
dbl
}
override def setFromDBObject(dbo: DBObject): Box[MyType] = {
val lst = dbo.keySet.toList
.map(k => enum.values.find(_.toString == dbo.get(k.toString)))
.filter(_.isDefined)
.map(_.get)
setBox(Full(lst)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment