| Module | Mongo::Collection::View::Readable |
| In: |
lib/mongo/collection/view/readable.rb
|
Defines read related behavior for collection view.
@since 2.0.0
| QUERY | = | '$query'.freeze |
The query modifier constant.
@since 2.2.0 |
|
| MODIFIERS | = | 'modifiers'.freeze |
The modifiers option constant.
@since 2.2.0 |
Execute an aggregation on the collection view.
@example Aggregate documents.
view.aggregate([
{ "$group" => { "_id" => "$city", "tpop" => { "$sum" => "$pop" }}}
])
@param [ Array<Hash> ] pipeline The aggregation pipeline. @param [ Hash ] options The aggregation options.
@return [ Aggregation ] The aggregation object.
@since 2.0.0
Allows the query to get partial results if some shards are down.
@example Allow partial results.
view.allow_partial_results
@return [ View ] The new view.
@since 2.0.0
Tell the query‘s cursor to stay open and wait for data.
@example Await data on the cursor.
view.await_data
@return [ View ] The new view.
@since 2.0.0
The number of documents returned in each batch of results from MongoDB.
@example Set the batch size.
view.batch_size(5)
@note Specifying 1 or a negative number is analogous to setting a limit.
@param [ Integer ] batch_size The size of each batch of results.
@return [ Integer, View ] Either the batch_size value or a new View.
@since 2.0.0
Associate a comment with the query.
@example Add a comment.
view.comment('slow query')
@note Set profilingLevel to 2 and the comment will be logged in the profile
collection along with the query.
@param [ String ] comment The comment to be associated with the query.
@return [ String, View ] Either the comment or a
new +View+.
@since 2.0.0
Get a count of matching documents in the collection.
@example Get the number of documents in the collection.
collection_view.count
@param [ Hash ] opts Options for the operation.
@option opts :skip [ Integer ] The number of documents to skip. @option opts :hint [ Hash ] Override default index selection and force
MongoDB to use a specific index for the query.
@option opts :limit [ Integer ] Max number of docs to count. @option opts :max_time_ms [ Integer ] The maximum amount of time to allow the
command to run.
@option opts [ Hash ] :read The read preference options. @option opts [ Hash ] :collation The collation to use. @option opts [ Mongo::Session ] :session The session to use for the operation.
@return [ Integer ] The document count.
@since 2.0.0
@deprecated Use count_documents or estimated_document_count instead. However, note that
the following operators will need to be substituted when switching to #count_documents:
* $where should be replaced with $expr (only works on 3.6+)
* $near should be replaced with $geoWithin with $center
* $nearSphere should be replaced with $geoWithin with $centerSphere
Get a count of matching documents in the collection.
@example Get the number of documents in the collection.
collection_view.count
@param [ Hash ] opts Options for the operation.
@option opts :skip [ Integer ] The number of documents to skip. @option opts :hint [ Hash ] Override default index selection and force
MongoDB to use a specific index for the query. Requires server version 3.6+.
@option opts :limit [ Integer ] Max number of docs to count. @option opts :max_time_ms [ Integer ] The maximum amount of time to allow the
command to run.
@option opts [ Hash ] :read The read preference options. @option opts [ Hash ] :collation The collation to use.
@return [ Integer ] The document count.
@since 2.6.0
Get a list of distinct values for a specific field.
@example Get the distinct values.
collection_view.distinct('name')
@param [ String, Symbol ] field_name The name of the field. @param [ Hash ] opts Options for the distinct command.
@option opts :max_time_ms [ Integer ] The maximum amount of time to allow the
command to run.
@option opts [ Hash ] :read The read preference options. @option opts [ Hash ] :collation The collation to use.
@return [ Array<Object> ] The list of distinct values.
@since 2.0.0
Gets an estimate of the count of documents in a collection using collection metadata.
@example Get the number of documents in the collection.
collection_view.estimated_document_count
@param [ Hash ] opts Options for the operation.
@option opts :max_time_ms [ Integer ] The maximum amount of time to allow the command to
run.
@option opts [ Hash ] :read The read preference options.
@return [ Integer ] The document count.
@since 2.6.0
Execute a map/reduce operation on the collection view.
@example Execute a map/reduce.
view.map_reduce(map, reduce)
@param [ String ] map The map js function. @param [ String ] reduce The reduce js function. @param [ Hash ] options The map/reduce options.
@return [ MapReduce ] The map reduce wrapper.
@since 2.0.0
The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.
@example Set the cursor to not timeout.
view.no_cursor_timeout
@return [ View ] The new view.
@since 2.0.0
The fields to include or exclude from each doc in the result set.
@example Set the fields to include or exclude.
view.projection(name: 1)
@note A value of 0 excludes a field from the doc. A value of 1 includes it.
Values must all be 0 or all be 1, with the exception of the _id value. The _id field is included by default. It must be excluded explicitly.
@param [ Hash ] document The field and 1 or 0, to include or exclude it.
@return [ Hash, View ] Either the fields or a new View.
@since 2.0.0
Set whether the disk location should be shown for each document.
@example Set show disk location option.
view.show_disk_loc(true)
@param [ true, false ] value The value for the field.
@return [ true, false, View ] Either the value or a new
+View+.
@since 2.0.0