Class: Mongo::Collection::View
- Inherits:
-
Object
- Object
- Mongo::Collection::View
- Extended by:
- Forwardable
- Includes:
- Enumerable, Explainable, Immutable, Iterable, Readable, Writable
- Defined in:
- lib/mongo/collection/view.rb,
lib/mongo/collection/view/iterable.rb,
lib/mongo/collection/view/readable.rb,
lib/mongo/collection/view/writable.rb,
lib/mongo/collection/view/immutable.rb,
lib/mongo/collection/view/map_reduce.rb,
lib/mongo/collection/view/aggregation.rb,
lib/mongo/collection/view/explainable.rb,
lib/mongo/collection/view/change_stream.rb,
lib/mongo/collection/view/builder/map_reduce.rb,
lib/mongo/collection/view/builder/aggregation.rb,
lib/mongo/collection/view/aggregation/behavior.rb,
lib/mongo/collection/view/change_stream/retryable.rb
Overview
The View
API is semipublic.
Representation of a query and options producing a result set of documents.
A View
can be modified using helpers. Helpers can be chained, as each one returns a View
if arguments are provided.
The query message is sent to the server when a “terminator” is called. For example, when #each is called on a View
, a Cursor object is created, which then sends the query to the server.
A View
is not created directly by a user. Rather, View
creates a View
when a CRUD operation is called and returns it to the user to interact with.
Defined Under Namespace
Modules: Builder, Explainable, Immutable, Iterable, Readable, Writable Classes: Aggregation, ChangeStream, MapReduce
Constant Summary
Constants included from Writable
Constants included from Explainable
Explainable::ALL_PLANS_EXECUTION, Explainable::EXECUTION_STATS, Explainable::QUERY_PLANNER
Instance Attribute Summary collapse
-
#collection ⇒ Collection
readonly
The
Collection
to query. -
#filter ⇒ Hash
(also: #selector)
readonly
The query filter.
-
#operation_timeout_ms ⇒ Integer | nil | The timeout_ms value that was passed as an option to the view.
readonly
private
Integer | nil | The timeout_ms value that was passed as an option to the view.
Attributes included from Mongo::CursorHost
Attributes included from Immutable
Instance Method Summary collapse
-
#==(other) ⇒ true, false
(also: #eql?)
Compare two
View
objects. -
#hash ⇒ Integer
A hash value for the
View
composed of the collection namespace, hash of the options and hash of the filter. -
#initialize(collection, filter = {}, options = {}) ⇒ View
constructor
Creates a new
View
. -
#inspect ⇒ String
Get a human-readable string representation of
View
. -
#operation_timeouts(opts = {}) ⇒ Hash
private
Timeout_ms value set on the operation level (if any), and/or timeout_ms that is set on collection/database/client level (if any).
-
#timeout_ms ⇒ Integer | nil
The timeout_ms value to use for this operation; either specified as an option to the view, or inherited from the collection.
-
#write_concern ⇒ Mongo::WriteConcern
Get the write concern on this
View
.
Methods included from Writable
#delete_many, #delete_one, #find_one_and_delete, #find_one_and_replace, #find_one_and_update, #replace_one, #update_many, #update_one
Methods included from Explainable
Methods included from Readable
#aggregate, #allow_disk_use, #allow_partial_results, #await_data, #batch_size, #comment, #count, #count_documents, #cursor_type, #distinct, #estimated_document_count, #hint, #limit, #map_reduce, #max_await_time_ms, #max_scan, #max_time_ms, #max_value, #min_value, #modifiers, #no_cursor_timeout, #parallel_scan, #projection, #read, #read_concern, #read_preference, #return_key, #show_disk_loc, #skip, #snapshot, #sort
Methods included from Iterable
Methods included from Mongo::CursorHost
Constructor Details
#initialize(collection, filter = {}, options = {}) ⇒ View
Creates a new View
.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/mongo/collection/view.rb', line 169 def initialize(collection, filter = {}, = {}) validate_doc!(filter) filter = BSON::Document.new(filter) = BSON::Document.new() @collection = collection @operation_timeout_ms = .delete(:timeout_ms) validate_timeout_mode!() # This is when users pass $query in filter and other modifiers # alongside? query = filter.delete(:$query) # This makes modifiers contain the filter if filter wasn't # given via $query but as top-level keys, presumably # downstream code ignores non-modifier keys in the modifiers? modifiers = filter.merge(.delete(:modifiers) || {}) @filter = (query || filter).freeze @options = Operation::Find::Builder::Modifiers.(modifiers).merge!().freeze end |
Instance Attribute Details
#collection ⇒ Collection (readonly)
Returns The Collection
to query.
56 57 58 |
# File 'lib/mongo/collection/view.rb', line 56 def collection @collection end |
#filter ⇒ Hash (readonly) Also known as: selector
Returns The query filter.
59 60 61 |
# File 'lib/mongo/collection/view.rb', line 59 def filter @filter end |
#operation_timeout_ms ⇒ Integer | nil | The timeout_ms value that was passed as an option to the view. (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Integer | nil | The timeout_ms value that was passed as an option to the view.
81 82 83 |
# File 'lib/mongo/collection/view.rb', line 81 def operation_timeout_ms @operation_timeout_ms end |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Compare two View
objects.
92 93 94 95 96 97 |
# File 'lib/mongo/collection/view.rb', line 92 def ==(other) return false unless other.is_a?(View) collection == other.collection && filter == other.filter && == other. end |
#hash ⇒ Integer
A hash value for the View
composed of the collection namespace, hash of the options and hash of the filter.
109 110 111 |
# File 'lib/mongo/collection/view.rb', line 109 def hash [ collection.namespace, .hash, filter.hash ].hash end |
#inspect ⇒ String
Get a human-readable string representation of View
.
207 208 209 210 |
# File 'lib/mongo/collection/view.rb', line 207 def inspect "#<Mongo::Collection::View:0x#{object_id} namespace='#{collection.namespace}'" + " @filter=#{filter.to_s} @options=#{.to_s}>" end |
#operation_timeouts(opts = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns timeout_ms value set on the operation level (if any), and/or timeout_ms that is set on collection/database/client level (if any).
228 229 230 231 232 233 234 235 236 |
# File 'lib/mongo/collection/view.rb', line 228 def operation_timeouts(opts = {}) {}.tap do |result| if opts[:timeout_ms] || operation_timeout_ms result[:operation_timeout_ms] = opts[:timeout_ms] || operation_timeout_ms else result[:inherited_timeout_ms] = collection.timeout_ms end end end |
#timeout_ms ⇒ Integer | nil
The timeout_ms value to use for this operation; either specified as an option to the view, or inherited from the collection.
195 196 197 |
# File 'lib/mongo/collection/view.rb', line 195 def timeout_ms operation_timeout_ms || collection.timeout_ms end |
#write_concern ⇒ Mongo::WriteConcern
Get the write concern on this View
.
220 221 222 |
# File 'lib/mongo/collection/view.rb', line 220 def write_concern WriteConcern.get([:write_concern] || [:write] || collection.write_concern) end |