문제

I'm trying to include the $setOnInsert field for Update and FindAndModify in ReactiveMongo. However, I can't seem to get it to work with the built in Commands.

Does anyone know how to include this field for updating a document?

도움이 되었습니까?

해결책

This simple example works for me:

val collection = ... // your collection goes here
collection.update(
  obj("_id" -> "1"),
  obj(
    "$setOnInsert" -> obj("field 1" -> "value 1"), 
    "$set" -> obj("field 2" -> "value 2")),
  upsert = true
).map {
  case n => println(n.ok.toString) // do smth
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top