Method: Mongoid::Collection#update

Defined in:
lib/mongoid/collection.rb

#update(selector, document, options = {}) ⇒ Object

Updates one or more documents in the collection.

Examples:

Update documents.

collection.update(
  { "_id" => BSON::OjectId.new },
  { "$push" => { "addresses" => { "_id" => "street" } } },
  :safe => true
)

Parameters:

  • selector (Hash)

    The document selector.

  • document (Hash)

    The modifier.

  • options (Hash) (defaults to: {})

    The options.

Since:

  • 2.0.0



144
145
146
147
148
149
150
151
# File 'lib/mongoid/collection.rb', line 144

def update(selector, document, options = {})
  updater = Threaded.update_consumer(klass)
  if updater
    updater.consume(selector, document, options)
  else
    master(options).update(selector, document, options)
  end
end