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',
  bypass_document_validation: 'bypassDocumentValidation',
  explain: 'explain',
  collation: 'collation',
  comment: 'comment',
  hint: 'hint',
  let: 'let',
  # This is intentional; max_await_time_ms is an alias for maxTimeMS
  # used on getMore commands for change streams.
  max_await_time_ms: 'maxTimeMS',
  max_time_ms: 'maxTimeMS'
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline, view, options) ⇒ Aggregation

Initialize the builder.

Parameters:

  • pipeline (Array<Hash>)

    The aggregation pipeline.

  • view (Collection::View)

    The collection view.

  • options (Hash)

    The map/reduce and read preference options.

Since:

  • 2.2.0



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

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



53
54
55
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 53

def options
  @options
end

#pipelineArray<Hash> (readonly)

Returns pipeline The pipeline.

Returns:

  • (Array<Hash>)

    pipeline The pipeline.

Since:

  • 2.2.0



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

def pipeline
  @pipeline
end

#viewCollection::View (readonly)

Returns view The collection view.

Returns:

Since:

  • 2.2.0



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

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



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

def specification
  spec = {
    selector: aggregation_command,
    db_name: database.name,
    read: @options[:read_preference] || view.read_preference,
    session: @options[:session],
    collation: @options[:collation],
  }
  spec.update(write_concern: write_concern) if write?
  spec
end