Class: Mongo::Collection::View::Builder::MapReduce
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Inherits: | Object |
Defined in: | lib/mongo/collection/view/builder/map_reduce.rb |
Overview
Builds a map/reduce specification from the view and options.
Constant Summary
-
MAPPINGS =
The mappings from ruby options to the map/reduce options.
BSON::Document.new( finalize: 'finalize', js_mode: 'jsMode', out: 'out', scope: 'scope', verbose: 'verbose', bypass_document_validation: 'bypassDocumentValidation', collation: 'collation', ).freeze
Class Method Summary
-
.new(map, reduce, view, options) ⇒ MapReduce
constructor
Initialize the builder.
Instance Attribute Summary
- #map ⇒ String readonly
- #options ⇒ Hash readonly
- #reduce ⇒ String readonly
- #view ⇒ Collection::View readonly
Instance Method Summary
-
#specification ⇒ Hash
Get the specification to pass to the map/reduce operation.
- #map_reduce_command private
- #view_options private
- #write?(spec) ⇒ Boolean private
Constructor Details
.new(map, reduce, view, options) ⇒ MapReduce
Initialize the builder.
Instance Attribute Details
#map ⇒ String
(readonly)
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 45
attr_reader :map
#options ⇒ Hash
(readonly)
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 54
attr_reader :
#reduce ⇒ String
(readonly)
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 48
attr_reader :reduce
#view ⇒ Collection::View (readonly)
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 51
attr_reader :view
Instance Method Details
#map_reduce_command (private)
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 103
def map_reduce_command command = BSON::Document.new( :mapReduce => collection.name, :map => map, :reduce => reduce, :query => filter, :out => { inline: 1 }, ) # Shouldn't this use self.read ? if collection.read_concern command[:readConcern] = Options::Mapper.transform_values_to_strings( collection.read_concern) end command.update( ) command.update( .slice(:collation)) # Read preference isn't simply passed in the command payload # (it may need to be converted to wire protocol flags). # Ideally it should be removed here, however due to Mongoid 7 # using this method and requiring :read to be returned from it, # we cannot do this just yet - see RUBY-2932. #command.delete(:read) command.merge!(Options::Mapper.transform_documents(, MAPPINGS)) command end
#specification ⇒ Hash
Get the specification to pass to the map/reduce operation.
# 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: [:session] } write?(spec) ? spec.merge!(write_concern: write_concern) : spec end
#view_options (private)
# File 'lib/mongo/collection/view/builder/map_reduce.rb', line 130
def @view_options ||= (opts = view. .dup opts.delete(:session) opts) end