The update
class method is actually Customer.with_default_scope.update
in disguise, that means that update
is actually the update
method from Mongoid::Criteria
and that looks like this:
# Update the first matching document atomically.
#
# @example Update the first matching document.
# context.update({ "$set" => { name: "Smiths" }})
#
# @param [ Hash ] attributes The new attributes for the document.
#
# @return [ nil, false ] False if no attributes were provided.
#
# @since 3.0.0
def update(attributes = nil)
update_documents(attributes)
end
Notice that it only takes a single attributes
parameter? That explains the error message. Presumably you're expecting update
to work the same way as it does in the MongoDB shell or the JavaScript interface.
First you need to find the document of interest and then call update
on that:
Customer.where('_id' => Moped::BSON::ObjectId(pk), 'contacts._id' => Moped::BSON::ObjectId(contact_pk))
.update($set => { 'contacts.$.first_name' => 'Bob' })