Class: Mongo::Collection::View
- Inherits:
-
Object
- Object
- Mongo::Collection::View
- Extended by:
- Forwardable
- 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/builder/flags.rb,
lib/mongo/collection/view/builder/op_query.rb,
lib/mongo/collection/view/builder/modifiers.rb,
lib/mongo/collection/view/builder/map_reduce.rb,
lib/mongo/collection/view/builder/aggregation.rb,
lib/mongo/collection/view/builder/find_command.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, MapReduce
Constant Summary
Constants included from Explainable
Explainable::ALL_PLANS_EXECUTION, Explainable::EXECUTION_STATS, Explainable::QUERY_PLANNER
Constants included from Readable
Readable::MODIFIERS, Readable::QUERY
Instance Attribute Summary collapse
-
#collection ⇒ Collection
readonly
The
Collection
to query. -
#filter ⇒ Hash
(also: #selector)
readonly
The query filter.
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 Retryable
#read_with_one_retry, #read_with_retry, #write_with_retry
Methods included from Readable
#aggregate, #allow_partial_results, #await_data, #batch_size, #comment, #count, #cursor_type, #distinct, #hint, #limit, #map_reduce, #max_await_time_ms, #max_scan, #max_time_ms, #max_value, #min_value, #modifiers, #no_cursor_timeout, #projection, #read, #return_key, #show_disk_loc, #skip, #snapshot, #sort
Methods included from Iterable
Constructor Details
#initialize(collection, filter = {}, options = {}) ⇒ View
Creates a new View
.
137 138 139 140 141 |
# File 'lib/mongo/collection/view.rb', line 137 def initialize(collection, filter = {}, = {}) validate_doc!(filter) @collection = collection parse_parameters!(BSON::Document.new(filter), BSON::Document.new()) end |
Instance Attribute Details
#collection ⇒ Collection (readonly)
Returns The Collection
to query.
53 54 55 |
# File 'lib/mongo/collection/view.rb', line 53 def collection @collection end |
#filter ⇒ Hash (readonly) Also known as: selector
Returns The query filter.
56 57 58 |
# File 'lib/mongo/collection/view.rb', line 56 def filter @filter end |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Compare two View
objects.
79 80 81 82 83 84 |
# File 'lib/mongo/collection/view.rb', line 79 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.
96 97 98 |
# File 'lib/mongo/collection/view.rb', line 96 def hash [ collection.namespace, .hash, filter.hash ].hash end |
#inspect ⇒ String
Get a human-readable string representation of View
.
151 152 153 154 |
# File 'lib/mongo/collection/view.rb', line 151 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
.
164 165 166 |
# File 'lib/mongo/collection/view.rb', line 164 def write_concern WriteConcern.get([:write] || [:write_concern] || collection.write_concern) end |