Module: Mongo::Collection::View::Aggregation::Behavior
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Instance Chain:
|
|
Defined in: | lib/mongo/collection/view/aggregation/behavior.rb |
Overview
Distills the behavior common to aggregator classes, like View::Aggregator and ::Mongo::Collection::View::ChangeStream
.
Constant Summary
::Mongo::Collection::View::Explainable
- Included
ALL_PLANS_EXECUTION, EXECUTION_STATS, QUERY_PLANNER
::Mongo::Loggable
- Included
Instance Attribute Summary
- #view ⇒ View readonly
-
#write? ⇒ Boolean
readonly
Internal use only
Internal use only
Whether this aggregation will write its result to a database collection.
::Mongo::Collection::View::Explainable
- Included
::Mongo::Collection::View::Iterable
- Included
#prefer_cached_cursor? | If the caching cursor is closed and was not fully iterated, the documents we have in it are not the complete result set and we have no way of completing that iteration. |
#use_query_cache? |
::Mongo::CursorHost
- Included
#cursor | Returns the cursor associated with this view, if any. |
#timeout_mode |
::Mongo::Collection::View::Immutable
- Included
Instance Method Summary
-
#allow_disk_use(value = nil) ⇒ true, ...
Set to true if disk usage is allowed during the aggregation.
-
#explain ⇒ Hash
Get the explain plan for the aggregation.
- #timeout_ms ⇒ Integer | nil Internal use only Internal use only
- #aggregate_spec(session, read_preference) private
-
#cache_options
private
Skip, sort, limit, projection are specified as pipeline stages rather than as options.
- #operation_timeouts(opts = {}) ⇒ Hash private Internal use only Internal use only
-
#perform_setup(view, options, forbid: [])
private
Common setup for all classes that include this behavior; the constructor should invoke this method.
- #server_selector private
::Mongo::Retryable
- Included
#read_worker | Returns the read worker for handling retryable reads. |
#select_server | This is a separate method to make it possible for the test suite to assert that server selection is performed during retry attempts. |
#write_worker | Returns the write worker for handling retryable writes. |
::Mongo::Loggable
- Included
#log_debug | Convenience method to log debug messages with the standard prefix. |
#log_error | Convenience method to log error messages with the standard prefix. |
#log_fatal | Convenience method to log fatal messages with the standard prefix. |
#log_info | Convenience method to log info messages with the standard prefix. |
#log_warn | Convenience method to log warn messages with the standard prefix. |
#logger | Get the logger instance. |
#_mongo_log_prefix, #format_message |
::Mongo::Collection::View::Explainable
- Included
#explain | Get the query plan for the query. |
#explain_options |
::Mongo::Collection::View::Iterable
- Included
#close_query | Cleans up resources associated with this query. |
#each | Iterate through documents returned by a query with this |
#kill_cursors | Alias for Iterable#close_query. |
#cache_options, #cached_cursor, #compute_limit_for_cached_query, #initial_query_op, | |
#maybe_set_tailable_options | Add tailable cusror options to the command specifiction if needed. |
#new_cursor_for_iteration | Start a new cursor for use when iterating (via #each). |
#oplog_replay, #select_cursor, #send_initial_query |
::Mongo::CursorHost
- Included
#validate_timeout_mode! | Ensure the timeout mode is appropriate for other options that have been given. |
::Mongo::Collection::View::Immutable
- Included
Instance Attribute Details
#view ⇒ View (readonly)
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 19
attr_reader :view
#write? ⇒ Boolean
(readonly)
Whether this aggregation will write its result to a database collection.
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 60
def write? pipeline.any? { |op| op.key?('$out') || op.key?(:$out) || op.key?('$merge') || op.key?(:$merge) } end
Instance Method Details
#aggregate_spec(session, read_preference) (private)
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 91
def aggregate_spec(session, read_preference) Builder::Aggregation.new( pipeline, view, .merge(session: session, read_preference: read_preference) ).specification end
#allow_disk_use(value = nil) ⇒ true
, ...
Set to true if disk usage is allowed during the aggregation.
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 38
def allow_disk_use(value = nil) configure(:allow_disk_use, value) end
#cache_options (private)
Skip, sort, limit, projection are specified as pipeline stages rather than as options.
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 101
def { namespace: collection.namespace, selector: pipeline, read_concern: view.read_concern, read_preference: view.read_preference, collation: [:collation], # Aggregations can read documents from more than one collection, # so they will be cleared on every write operation. multi_collection: true, } end
#explain ⇒ Hash
Get the explain plan for the aggregation.
#operation_timeouts(opts = {}) ⇒ Hash
(private)
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 118
def operation_timeouts(opts = {}) {}.tap do |result| if opts[:timeout_ms] || @timeout_ms result[:operation_timeout_ms] = opts.delete(:timeout_ms) || @timeout_ms else result[:inherited_timeout_ms] = view.timeout_ms end end end
#perform_setup(view, options, forbid: []) (private)
Common setup for all classes that include this behavior; the constructor should invoke this method.
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 76
def perform_setup(view, , forbid: []) @view = view @timeout_ms = .delete(:timeout_ms) @options = BSON::Document.new( ).freeze yield validate_timeout_mode!(, forbid: forbid) end
#server_selector (private)
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 87
def server_selector @view.send(:server_selector) end
#timeout_ms ⇒ Integer
| nil
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 68
def timeout_ms @timeout_ms || view.timeout_ms end