Method: Mongo::Collection#update_many
- Defined in:
- lib/mongo/collection.rb
#update_many(filter, update, options = {}) ⇒ Result
Update documents in the collection.
Examples:
Update multiple documents in the collection.
Update multiple documents in the collection.
collection.update_many({ name: 'test'}, '$set' => { name: 'test1' })
Parameters:
-
filter
(Hash)
—
The filter to use.
-
update
(Hash | Array<Hash>)
—
The update document or pipeline.
-
options
(Hash)
(defaults to: {})
—
The options.
Options Hash (options):
-
:upsert
(true | false)
—
Whether to upsert if the document doesn’t exist.
-
:bypass_document_validation
(true | false)
—
Whether or not to skip document level validation.
-
:collation
(Hash)
—
The collation to use.
-
:array_filters
(Array)
—
A set of filters specifying to which array elements an update should apply.
-
:session
(Session)
—
The session to use.
-
:timeout_ms
(Integer)
—
The operation timeout in milliseconds. Must be a non-negative integer. An explicit value of 0 means infinite. The default value is unset which means the value is inherited from the collection or the database or the client.
-
:hint
(Hash | String)
—
The index to use for this operation. May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. “id”).
-
:let
(Hash)
—
Mapping of variables to use in the command. See the server documentation for details.
Returns:
-
(Result)
—
The response from the database.
Since:
-
2.1.0
1094 1095 1096 |
# File 'lib/mongo/collection.rb', line 1094 def update_many(filter, update, options = {}) find(filter, options).update_many(update, options) end |