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

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
build/ruby-driver-master/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



64
65
66
67
68
# File 'build/ruby-driver-master/lib/mongo/collection/view/builder/aggregation.rb', line 64

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



55
56
57
# File 'build/ruby-driver-master/lib/mongo/collection/view/builder/aggregation.rb', line 55

def options
  @options
end

#pipelineArray<Hash> (readonly)

Returns pipeline The pipeline.

Returns:

  • (Array<Hash>)

    pipeline The pipeline.

Since:

  • 2.2.0



49
50
51
# File 'build/ruby-driver-master/lib/mongo/collection/view/builder/aggregation.rb', line 49

def pipeline
  @pipeline
end

#viewCollection::View (readonly)

Returns view The collection view.

Returns:

Since:

  • 2.2.0



52
53
54
# File 'build/ruby-driver-master/lib/mongo/collection/view/builder/aggregation.rb', line 52

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



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'build/ruby-driver-master/lib/mongo/collection/view/builder/aggregation.rb', line 78

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