Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def nextID(name: String): Future[Int] = {
- val query = BSONDocument("name" -> BSONString(name))
- val update = Update(BSONDocument("$inc" -> BSONDocument("counter" -> BSONInteger(1))), true)
- val command = FindAndModify("counters", query, update, upsert = true)
- db.command(command) map { docOpt ⇒
- docOpt match {
- case Some(document) ⇒
- document.get("counter") match {
- case Some(BSONInteger(counter)) ⇒ counter
- case _ ⇒ 0
- }
- case _ ⇒ 0
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement