Skip to content

Instantly share code, notes, and snippets.

@alexy
Created April 11, 2012 00:56
Show Gist options
  • Save alexy/2356032 to your computer and use it in GitHub Desktop.
Save alexy/2356032 to your computer and use it in GitHub Desktop.
finding and updating a mongo object with casbah, clueless edition
def putStat[T](id: String, k: String, v: T, coll: MongoCollection = ms): Unit = {
Console.err.println("putting mongo stat: _id->%s, %s->%s".format(id,k,v))
val newVal = Map(k -> v)
coll.findOneByID(id) match {
case Some(obj) => coll.update(obj, obj + (k -> v))
case _ => coll.insert(MongoDBObject("_id"->id, k->v))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment