Class: Mongo::Collection::View::Builder::Aggregation

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mongo/collection/view/builder/aggregation.rb

Overview

Builds an aggregation command specification from the view and options.

Since:

  • 2.2.0

Constant Summary

MAPPINGS =

The mappings from ruby options to the aggregation options.

Since:

  • 2.2.0

BSON::Document.new(
  :allow_disk_use => 'allowDiskUse',
  :max_time_ms => 'maxTimeMS',
  # This is intentional; max_await_time_ms is an alias for maxTimeMS used on getmore
  # commands for change streams.
  :max_await_time_ms => 'maxTimeMS',
  :explain => 'explain',
  :bypass_document_validation => 'bypassDocumentValidation',
  :collation => 'collation',
  :hint => 'hint',
  :comment => 'comment'
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline, view, options) ⇒ Aggregation

Initialize the builder.

Examples:

Initialize the builder.

Aggregation.new(map, reduce, view, options)

Parameters:

  • pipeline (Array<Hash>)

    The aggregation pipeline.

  • view (Collection::View)

    The collection view.

  • options (Hash)

    The map/reduce options.

Since:

  • 2.2.0



63
64
65
66
67
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 63

def initialize(pipeline, view, options)
  @pipeline = pipeline
  @view = view
  @options = options
end

Instance Attribute Details

#optionsHash (readonly)

Returns options The map/reduce specific options.

Returns:

  • (Hash)

    options The map/reduce specific options.

Since:

  • 2.2.0



51
52
53
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 51

def options
  @options
end

#pipelineArray<Hash> (readonly)

Returns pipeline The pipeline.

Returns:

  • (Array<Hash>)

    pipeline The pipeline.

Since:

  • 2.2.0



45
46
47
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 45

def pipeline
  @pipeline
end

#viewCollection::View (readonly)

Returns view The collection view.

Returns:

Since:

  • 2.2.0



48
49
50
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 48

def view
  @view
end

Instance Method Details

#specificationHash

Get the specification to pass to the aggregation operation.

Examples:

Get the specification.

builder.specification

Returns:

  • (Hash)

    The specification.

Since:

  • 2.2.0



77
78
79
80
81
82
83
84
85
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 77

def specification
  spec = {
          selector: aggregation_command,
          db_name: database.name,
          read: read,
          session: @options[:session]
         }
  write? ? spec.merge!(write_concern: write_concern) : spec
end