lib/mongoid/persistable/updatable.rb
# Update the document in the database.
#
# @example Update an existing document.
#   document.update
#
# @param [ Hash ] options Options to pass to update.
#
# @option options [ true, false ] :validate Whether or not to validate.
#
# @return [ true, false ] True if succeeded, false if not.
Update the document in the database.
Update the document in the database .
def update_document(options = {})
        prepare_update(options) do
          updates, conflicts = init_atomic_updates
          unless updates.empty?
            coll = collection(_root)
            selector = atomic_selector
            coll.find(selector).update_one(positionally(selector, updates), session: _session)
             TODO: MONGOID-5026: reduce the number of writes performed by
             more intelligently combining the writes such that there are
             fewer conflicts.
            conflicts.each_pair do |modifier, changes|
               Group the changes according to their root key which is
               the top-level association name.
               This handles at least the cases described in MONGOID-4982.
              conflicting_change_groups = changes.group_by do |key, _|
                key.split(".", 2).first
              end.values
               Apply changes in batches. Pop one change from each
               field-conflict group round-robin until all changes
               have been applied.
              while batched_changes = conflicting_change_groups.map(&:pop).compact.to_h.presence
                coll.find(selector).update_one(
                  positionally(selector, modifier => batched_changes),
                  session: _session,
                )
              end
            end
          end
        end
      end
def update_document ( options = { } ) prepare_update ( options ) do updates , conflicts = init_atomic_updates unless updates . empty? coll = collection ( _root ) selector = atomic_selector coll . find ( selector ) . update_one ( positionally ( selector , updates ) , session : _session ) conflicts . each_pair do | modifier , changes | conflicting_change_groups = changes . group_by do | key , _ | key . split ( "." , 2 ) . first end . values while batched_changes = conflicting_change_groups . map ( & :pop ) . compact . to_h . presence coll . find ( selector ) . update_one ( positionally ( selector , modifier => batched_changes ) , session : _session , ) end end end end end
Update the document in the database.
Update the document in the database .
# The following code applies updates which would cause # path conflicts in MongoDB, for example when changing attributes # of foo.0.bars while adding another foo. Each conflicting update # is applied using its own write. # # TODO: MONGOID-5026: reduce the number of writes performed by # more intelligently combining the writes such that there are # fewer conflicts. # Group the changes according to their root key which is # the top-level association name. # This handles at least the cases described in MONGOID-4982. # Apply changes in batches. Pop one change from each # field-conflict group round-robin until all changes # have been applied.
True if succeeded, false if not.
True if succeeded false if not .
 true, false 
options
:validate Whether or not to validate.
: validate Whether or not to validate .
<not_specific>
options Options to pass to update.
options Options to pass to update .
example
Update an existing document. document.update
Update an existing document . document . update