Class: Mongo::Collection::View::Builder::Aggregation
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Inherits: | Object |
Defined in: | lib/mongo/collection/view/builder/aggregation.rb |
Overview
Builds an aggregation command specification from the view and options.
Constant Summary
-
MAPPINGS =
The mappings from ruby options to the aggregation options.
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
Class Method Summary
-
.new(pipeline, view, options) ⇒ Aggregation
constructor
Initialize the builder.
Instance Attribute Summary
- #options ⇒ Hash readonly
- #pipeline ⇒ Array<Hash> readonly
- #view ⇒ Collection::View readonly
- #write? ⇒ Boolean readonly private
Instance Method Summary
-
#specification ⇒ Hash
Get the specification to pass to the aggregation operation.
- #aggregation_command private
- #batch_size_doc private
Constructor Details
.new(pipeline, view, options) ⇒ Aggregation
Initialize the builder.
Instance Attribute Details
#options ⇒ Hash
(readonly)
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 55
attr_reader :
#pipeline ⇒ Array
<Hash
> (readonly)
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 49
attr_reader :pipeline
#view ⇒ Collection::View (readonly)
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 52
attr_reader :view
#write? ⇒ Boolean
(readonly, private)
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 94
def write? pipeline.any? do |operator| operator[:$out] || operator['$out'] || operator[:$merge] || operator['$merge'] end end
Instance Method Details
#aggregation_command (private)
# File 'lib/mongo/collection/view/builder/aggregation.rb', line 101
def aggregation_command command = BSON::Document.new # aggregate must be the first key in the command document if view.is_a?(Collection::View) command[:aggregate] = collection.name elsif view.is_a?(Database::View) command[:aggregate] = 1 else raise ArgumentError, "Unknown view class: #{view}" end command[:pipeline] = pipeline if read_concern = view.read_concern command[:readConcern] = Options::Mapper.transform_values_to_strings( read_concern) end command[:cursor] = batch_size_doc command.merge!(Options::Mapper.transform_documents(, MAPPINGS)) command end
#batch_size_doc (private)
#specification ⇒ Hash
Get the specification to pass to the aggregation operation.
# File '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