Class: Mongo::Collection::View
- Inherits:
-
Object
- Object
- Mongo::Collection::View
- Extended by:
- Forwardable
- Includes:
- Enumerable, Explainable, Immutable, Iterable, Readable, Writable
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/collection/view.rb,
build/ruby-driver-v2.19/lib/mongo/collection/view/iterable.rb,
build/ruby-driver-v2.19/lib/mongo/collection/view/readable.rb,
build/ruby-driver-v2.19/lib/mongo/collection/view/writable.rb,
build/ruby-driver-v2.19/lib/mongo/collection/view/immutable.rb,
build/ruby-driver-v2.19/lib/mongo/collection/view/map_reduce.rb,
build/ruby-driver-v2.19/lib/mongo/collection/view/aggregation.rb,
build/ruby-driver-v2.19/lib/mongo/collection/view/explainable.rb,
build/ruby-driver-v2.19/lib/mongo/collection/view/change_stream.rb,
build/ruby-driver-v2.19/lib/mongo/collection/view/builder/map_reduce.rb,
build/ruby-driver-v2.19/lib/mongo/collection/view/builder/aggregation.rb,
build/ruby-driver-v2.19/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.
Attributes included from Iterable
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
. -
#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, #projection, #read, #read_concern, #read_preference, #return_key, #show_disk_loc, #skip, #snapshot, #sort
Methods included from Iterable
Constructor Details
#initialize(collection, filter = {}, options = {}) ⇒ View
Creates a new View
.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view.rb', line 155 def initialize(collection, filter = {}, = {}) validate_doc!(filter) @collection = collection filter = BSON::Document.new(filter) = BSON::Document.new() # 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 'build/ruby-driver-v2.19/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 'build/ruby-driver-v2.19/lib/mongo/collection/view.rb', line 59 def filter @filter end |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Compare two View
objects.
86 87 88 89 90 91 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view.rb', line 86 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.
103 104 105 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view.rb', line 103 def hash [ collection.namespace, .hash, filter.hash ].hash end |
#inspect ⇒ String
Get a human-readable string representation of View
.
181 182 183 184 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view.rb', line 181 def inspect "#<Mongo::Collection::View:0x#{object_id} namespace='#{collection.namespace}'" + " @filter=#{filter.to_s} @options=#{.to_s}>" end |
#write_concern ⇒ Mongo::WriteConcern
Get the write concern on this View
.
194 195 196 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view.rb', line 194 def write_concern WriteConcern.get([:write_concern] || [:write] || collection.write_concern) end |