Method: Mongo::Collection#aggregate
- Defined in:
- lib/mongo/collection.rb
#aggregate(pipeline, options = {}) ⇒ View::Aggregation
Perform an aggregation on the collection.
Examples:
Perform an aggregation.
Perform an aggregation.
collection.aggregate([ { "$group" => { "_id" => "$city", "tpop" => { "$sum" => "$pop" }}} ])
Parameters:
-
pipeline
(Array<Hash>)
—
The aggregation pipeline.
-
options
(Hash)
(defaults to: {})
—
The aggregation options.
Options Hash (options):
-
:allow_disk_use
(true | false)
—
Set to true if disk usage is allowed during the aggregation.
-
:batch_size
(Integer)
—
The number of documents to return per batch.
-
:bypass_document_validation
(true | false)
—
Whether or not to skip document level validation.
-
:collation
(Hash)
—
The collation to use.
-
:comment
(Object)
—
A user-provided comment to attach to this command.
-
:hint
(String)
—
The index to use for the aggregation.
-
:let
(Hash)
—
Mapping of variables to use in the pipeline. See the server documentation for details.
-
:max_time_ms
(Integer)
—
The maximum amount of time to allow the query to run, in milliseconds. This option is deprecated, use :timeout_ms instead.
-
: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.
Returns:
-
(View::Aggregation)
—
The aggregation object.
Since:
-
2.1.0
575 576 577 |
# File 'lib/mongo/collection.rb', line 575 def aggregate(pipeline, options = {}) View.new(self, {}, options).aggregate(pipeline, options) end |