2015년 1월 1일 목요일

Mongo + Scala: Update multiple documents

I have the following code at scala that updates mongo, but it only updates one document, how do I get it to update multiple documents?

def pullOnStart(): DBObject = {
    val gooserQuery = MongoDBObject("status" -> MongoDBObject("gooser" -> "taken"))
    val gooserUpdate = MongoDBObject("status" -> MongoDBObject("loader" -> "green"))
    val gooserUpdateSet = MongoDBObject("$set" -> gooserUpdate)
    collection.findAndModify(gooserQuery, gooserUpdateSet) match {
      case Some(doc) =>
        doc.put("status", MongoDBObject("loader" -> "green"))
        doc
      case None => null
    }
    
    val phanterTakenGet = MongoDBObject("status" -> MongoDBObject("phanter" -> "taken"))
    val phanterTakenSet = MongoDBObject("status" -> MongoDBObject("gooser" -> "yellow"))
    val setPhanter = MongoDBObject("$set" -> phanterTakenSet)
    collection.findAndModify(phanterTakenGet, setPhanter) match {
      case Some(doc) =>
        doc.put("status", MongoDBObject("loader" -> "green"))
        doc
      case None => null
    }
  }

댓글 없음:

댓글 쓰기