Problems with findOneAndUpdate and updateOne

Hi,

I have a “simple” problem, what I can’t solute myself.
I wrote a small java class which uses the reactive mongodb lib: mongodb-driver-reactivestreams
Here is the class: https://pastebin.com/Ddfz6pq7
The idea is to create a object and call connect to connect this object with a mongodb database and to choose a collection.

Now my problem. The updateOne method doesn’t have any effect.
Here the entry of the players connection which should be updated:

_id: 5f3271160ef36644c04d61fb
requested: null
role: "STAFF"
discordID: null
balance: 316.3
town: "Tutorial"
lastDonation: "0"
referredBy: "x"
name: "Tockra"
uuid: "abcd"

So I call updateOne with a uuid filter (abcd) and a new entry which should update all stuff:

[12:51:57 INFO]: FILTERDOC: {"uuid": "abcd"}
[12:51:57 INFO]: PLAYER: {"requested": null, "role": "STAFF", "discordID": null, "balance": 317.3, "town": "Tutorial", "referredBy": "x", "lastDonation": "0", "name": "Tockra", "uuid": "abcd"}

After looking into the database with mongodb compass the balance (which is the only changed value), isn’t changed…

What did I wrong?

T

€dit: If I replace updateOne with replaceOne it works. But why?

Thinking you want to find and update the document in its entirety.In that case use replace one by providing the replacement document.If you only updating specific keys in the document would suggest to supply an update operator expression to the second parameter of findOneAndUpdate such as $set,$unset.

But why doesn’t that work with updateOne?

Because the mechanics of the operators are different. That is why you have replace for that use case.Granted you could use $set and pass to it the keys to update.But if you want to replace the entire document then that would save you from the over head of updating every key.I hope this helps with answering your question.