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 collapse

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',
  :explain => 'explain',
  :bypass_document_validation => 'bypassDocumentValidation'
).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



57
58
59
60
61
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 57

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



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

def options
  @options
end

#pipelineArray<Hash> (readonly)

Returns pipeline The pipeline.

Returns:

  • (Array<Hash>)

    pipeline The pipeline.

Since:

  • 2.2.0



39
40
41
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 39

def pipeline
  @pipeline
end

#viewCollection::View (readonly)

Returns view The collection view.

Returns:

Since:

  • 2.2.0



42
43
44
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 42

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



71
72
73
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 71

def specification
  { selector: aggregation_command, db_name: database.name, read: read }
end