Skip to content

Instantly share code, notes, and snippets.

@srenault
srenault / a-json-mongo.scala
Last active December 20, 2015 02:59 — forked from playxamplez-admin/CODE
Flatten #json object for partial update with #ReactiveMongo #play2.1
def flattenObject(obj: JsObject, prefix: Option[String] = None) :Seq[(String, JsValue)] = {
obj.fields.toList match {
case ("$date",_) :: Nil if prefix.isDefined => Seq(prefix.get -> obj)
case ("$date",_) :: Nil => throw new Exception("Can't save $date at the first level.")
case fs => fs.flatMap { t =>
val name = prefix.map(_ + ".").getOrElse("") + t._1
t._2 match {
case obj: JsObject => flattenObject(obj, Some(name))
case value => Seq(name -> value)
}
@srenault
srenault / allfragments.json
Created June 21, 2016 15:02 — forked from lamenath/allfragments.json
all prismic fragments document mask
{
"Basic Types" : {
"uid" : {
"type" : "UID",
"config" : {
"placeholder" : "Unique Document Identifier"
}
},
"text" : {
"type" : "Text",