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



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

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



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

def options
  @options
end

#pipelineArray<Hash> (readonly)

Returns pipeline The pipeline.

Returns:

  • (Array<Hash>)

    pipeline The pipeline.

Since:

  • 2.2.0



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

def pipeline
  @pipeline
end

#viewCollection::View (readonly)

Returns view The collection view.

Returns:

Since:

  • 2.2.0



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

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



73
74
75
76
77
78
79
80
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 73

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