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

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



64
65
66
67
68
69
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 64

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



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

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



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

def options
  @options
end

#reduceString (readonly)

Returns reduce The reduce function.

Returns:

  • (String)

    reduce The reduce function.

Since:

  • 2.2.0



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

def reduce
  @reduce
end

#viewCollection::View (readonly)

Returns view The collection view.

Returns:

Since:

  • 2.2.0



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

def view
  @view
end

Instance Method Details

#command_specificationHash

Get the specification for issuing a find command on the map/reduce results.

Examples:

Get the command specification.

builder.command_specification

Returns:

  • (Hash)

    The specification.

Since:

  • 2.2.0



80
81
82
83
84
85
86
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 80

def command_specification
  {
    selector: find_command,
    db_name: query_database,
    read: read
  }
end

#query_specificationHash

Get the specification for the document query after a map/reduce.

Examples:

Get the query specification.

builder.query_specification

Returns:

  • (Hash)

    The specification.

Since:

  • 2.2.0



96
97
98
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 96

def query_specification
  { selector: {}, options: {}, db_name: query_database, coll_name: query_collection }
end

#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



108
109
110
111
112
113
114
115
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 108

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