Class: Mongo::Collection::View::Builder::MapReduce

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

Overview

Builds a map/reduce specification from the view and options.

Since:

  • 2.2.0

Constant Summary collapse

MAPPINGS =

The mappings from ruby options to the map/reduce options.

Since:

  • 2.2.0

BSON::Document.new(
  finalize: 'finalize',
  js_mode: 'jsMode',
  out: 'out',
  scope: 'scope',
  verbose: 'verbose',
  bypass_document_validation: 'bypassDocumentValidation',
  collation: 'collation',
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map, reduce, view, options) ⇒ MapReduce

Initialize the builder.

Examples:

Initialize the builder.

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

Parameters:

  • map (String)

    The map function.

  • reduce (String)

    The reduce function.

  • view (Collection::View)

    The collection view.

  • options (Hash)

    The map/reduce options.

Since:

  • 2.2.0



67
68
69
70
71
72
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 67

def initialize(map, reduce, view, options)
  @map = map
  @reduce = reduce
  @view = view
  @options = options
end

Instance Attribute Details

#mapString (readonly)

Returns map The map function.

Returns:

  • (String)

    map The map function.

Since:

  • 2.2.0



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

def map
  @map
end

#optionsHash (readonly)

Returns options The map/reduce specific options.

Returns:

  • (Hash)

    options The map/reduce specific options.

Since:

  • 2.2.0



54
55
56
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 54

def options
  @options
end

#reduceString (readonly)

Returns reduce The reduce function.

Returns:

  • (String)

    reduce The reduce function.

Since:

  • 2.2.0



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

def reduce
  @reduce
end

#viewCollection::View (readonly)

Returns view The collection view.

Returns:

Since:

  • 2.2.0



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

def view
  @view
end

Instance Method Details

#specificationHash

Get the specification to pass to the map/reduce operation.

Examples:

Get the specification.

builder.specification

Returns:

  • (Hash)

    The specification.

Since:

  • 2.2.0



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 82

def specification
  spec = {
    selector: map_reduce_command,
    db_name: database.name,
    # Note that selector just above may also have a read preference
    # specified, per the #map_reduce_command method below.
    read: read,
    session: options[:session]
  }
  write?(spec) ? spec.merge!(write_concern: write_concern) : spec
end