Reputation: 339
I'm using Elixir MongoDB driver. I need to update an existing document. What I'm trying to do:
Mongo.find_one_and_update(:mongo, "users", %{user_id: 1}, %{money: 100}, pool: DBConnection.Poolboy)
But it throws an error:
** (ArgumentError) update only allows atomic modifiers, got: money (mongodb) lib/mongo.ex:788: Mongo.modifier_key/2 (mongodb) lib/mongo.ex:173: Mongo.find_one_and_update/5
What is the proper way to update document? Thank you.
Upvotes: 0
Views: 529
Reputation: 222108
To set fields in an update in MongoDB, you need to put the fields to update in a map with key :"$set"
:
Mongo.find_one_and_update(:mongo, "users", %{user_id: 1}, %{"$set": %{money: 100}}, ...)
Upvotes: 3