Я могу вставлять, читать и удалять, но я не могу получить updateOne или updateMany для изменения документов.Коллекция драйверов Mongo Scala не обновляет документ
Я использую MongoDB 3.2.7 с libraryDependencies + = "org.mongodb.scala" %% "Монго-Скала-драйвер" % "1.1.1"
def read() = {
val query = Document("title" -> "Text Tiling")
methods.find(query).subscribe(
(method: Document) => update(method.toJson()), // onNext
(error: Throwable) => Logger.debug(s"Query failed: ${error.getMessage}"), // onError
() => Logger.debug("onComplete") // onComplete
)}
def update(jsonSting:String): Unit = {
Logger.debug("update() " + jsonSting)
Logger.debug(methods.find().first().toString)
val observer = new Observer[UpdateResult] {
override def onSubscribe(subscription: Subscription): Unit = {
Logger.debug("onSubscribe: " + subscription.toString)
}
override def onComplete: Unit = {
Logger.debug("onComplete")
}
override def onError(e: Throwable): Unit = {
Logger.debug("onError: " + e.getMessage)
}
override def onNext(doc: UpdateResult) {
Logger.debug("onNext")
}
}
val filter = Document("title" -> "Text Tiling")
val mod = Document("$set" -> Document("reputation" -> 5))
val result = methods.updateOne(filter,mod).subscribe(observer)
Logger.debug("result: " + result)}
Вот журналы:
[отладка] приложения - обновление() { "_id": { "$ подъязычная": "5759542a4e0bf602adcab149"}, "название": "Текст Черепица", "репутация": 0}
[отладка] application - [email protected]
[отладка] приложение - onSubscribe: [email protected]
[отладка] приложение - результат:()
[отладка] приложение - OnComplete