Class Mongo::Collection::View
In: lib/mongo/collection/view.rb
lib/mongo/collection/view/builder/op_query.rb
lib/mongo/collection/view/builder/modifiers.rb
lib/mongo/collection/view/builder/find_command.rb
lib/mongo/collection/view/builder/map_reduce.rb
lib/mongo/collection/view/builder/flags.rb
lib/mongo/collection/view/builder/aggregation.rb
lib/mongo/collection/view/explainable.rb
lib/mongo/collection/view/change_stream.rb
lib/mongo/collection/view/readable.rb
lib/mongo/collection/view/map_reduce.rb
lib/mongo/collection/view/change_stream/retryable.rb
lib/mongo/collection/view/aggregation.rb
lib/mongo/collection/view/iterable.rb
lib/mongo/collection/view/writable.rb
lib/mongo/collection/view/immutable.rb
Parent: Object

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.

@note The View API is semipublic. @api semipublic

Methods

==   eql?   hash   inspect   new   write_concern  

Included Modules

Enumerable Immutable Iterable Readable Retryable Explainable Writable

Classes and Modules

Module Mongo::Collection::View::Builder
Module Mongo::Collection::View::Explainable
Module Mongo::Collection::View::Immutable
Module Mongo::Collection::View::Iterable
Module Mongo::Collection::View::Readable
Module Mongo::Collection::View::Writable
Class Mongo::Collection::View::Aggregation
Class Mongo::Collection::View::ChangeStream
Class Mongo::Collection::View::MapReduce

External Aliases

filter -> selector

Attributes

collection  [R]  @return [ Collection ] The Collection to query.
filter  [R]  @return [ Hash ] The query filter.

Public Class methods

Creates a new View.

@example Find all users named Emily.

  View.new(collection, {:name => 'Emily'})

@example Find all users named Emily skipping 5 and returning 10.

  View.new(collection, {:name => 'Emily'}, :skip => 5, :limit => 10)

@example Find all users named Emily using a specific read preference.

  View.new(collection, {:name => 'Emily'}, :read => :secondary_preferred)

@param [ Collection ] collection The Collection to query. @param [ Hash ] filter The query filter. @param [ Hash ] options The additional query options.

@option options :comment [ String ] Associate a comment with the query. @option options :batch_size [ Integer ] The number of docs to return in

  each response from MongoDB.

@option options :fields [ Hash ] The fields to include or exclude in

  returned docs.

@option options :hint [ Hash ] Override default index selection and force

  MongoDB to use a specific index for the query.

@option options :limit [ Integer ] Max number of docs to return. @option options :max_scan [ Integer ] Constrain the query to only scan the

  specified number of docs. Use to prevent queries from running too long.
  Deprecated as of MongoDB server version 4.0.

@option options :read [ Symbol ] The read preference to use for the query.

  If none is provided, the collection's default read preference is used.

@option options :show_disk_loc [ true, false ] Return disk location info as

  a field in each doc.

@option options :skip [ Integer ] The number of documents to skip. @option options :snapshot [ true, false ] Prevents returning a doc more than

  once. Deprecated as of MongoDB server version 4.0.

@option options :sort [ Hash ] The key and direction pairs used to sort the

  results.

@option options [ Hash ] :collation The collation to use.

@since 2.0.0

Public Instance methods

Compare two View objects.

@example Compare the view with another object.

  view == other

@return [ true, false ] Equal if collection, filter, and options of two

  +View+ match.

@since 2.0.0

eql?(other)

Alias for #==

A hash value for the View composed of the collection namespace, hash of the options and hash of the filter.

@example Get the hash value.

  view.hash

@return [ Integer ] A hash value of the View object.

@since 2.0.0

Get a human-readable string representation of View.

@example Get the inspection.

  view.inspect

@return [ String ] A string representation of a View instance.

@since 2.0.0

Get the write concern on this View.

@example Get the write concern.

  view.write_concern

@return [ Mongo::WriteConcern ] The write concern.

@since 2.0.0

[Validate]