Class: Mongo::Database::View
- Inherits:
-
Object
- Object
- Mongo::Database::View
- Extended by:
- Forwardable
- Includes:
- Enumerable, Retryable
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/database/view.rb
Overview
A class representing a view of a database.
Instance Attribute Summary collapse
-
#batch_size ⇒ Integer
readonly
Batch_size The size of the batch of results when sending the listCollections command.
-
#collection ⇒ Collection
readonly
Collection The command collection.
- #database ⇒ Object readonly private
-
#limit ⇒ Integer
readonly
Limit The limit when sending a command.
Instance Method Summary collapse
-
#aggregate(pipeline, options = {}) ⇒ Collection::View::Aggregation
private
Execute an aggregation on the database view.
-
#collection_names(options = {}) ⇒ Array<String>
Get all the names of the non-system collections in the database.
-
#initialize(database) ⇒ View
constructor
Create the new database view.
-
#list_collections(options = {}) ⇒ Array<Hash>
Get info on all the collections in the database.
Methods included from Retryable
#read_worker, #select_server, #write_worker
Constructor Details
Instance Attribute Details
#batch_size ⇒ Integer (readonly)
Returns batch_size The size of the batch of results when sending the listCollections command.
36 37 38 |
# File 'build/ruby-driver-v2.19/lib/mongo/database/view.rb', line 36 def batch_size @batch_size end |
#collection ⇒ Collection (readonly)
Returns collection The command collection.
42 43 44 |
# File 'build/ruby-driver-v2.19/lib/mongo/database/view.rb', line 42 def collection @collection end |
#database ⇒ Object (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.
135 136 137 |
# File 'build/ruby-driver-v2.19/lib/mongo/database/view.rb', line 135 def database @database end |
#limit ⇒ Integer (readonly)
Returns limit The limit when sending a command.
39 40 41 |
# File 'build/ruby-driver-v2.19/lib/mongo/database/view.rb', line 39 def limit @limit end |
Instance Method Details
#aggregate(pipeline, options = {}) ⇒ Collection::View::Aggregation
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.
Execute an aggregation on the database view.
151 152 153 |
# File 'build/ruby-driver-v2.19/lib/mongo/database/view.rb', line 151 def aggregate(pipeline, = {}) Collection::View::Aggregation.new(self, pipeline, ) end |
#collection_names(options = {}) ⇒ Array<String>
The set of returned collection names depends on the version of MongoDB server that fulfills the request.
Get all the names of the non-system collections in the database.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'build/ruby-driver-v2.19/lib/mongo/database/view.rb', line 67 def collection_names( = {}) @batch_size = [:batch_size] session = client.send(:get_session, ) cursor = read_with_retry_cursor(session, ServerSelector.primary, self) do |server| send_initial_query(server, session, .merge(name_only: true)) end cursor.map do |info| if cursor.initial_result.connection_description.features.list_collections_enabled? info['name'] else (info['name'] && info['name'].sub("#{@database.name}.", '')) end end.reject do |name| name.start_with?('system.') || name.include?('$') end end |
#list_collections(options = {}) ⇒ Array<Hash>
The set of collections returned, and the schema of the information hash per collection, depends on the MongoDB server version that fulfills the request.
Get info on all the collections in the database.
114 115 116 117 |
# File 'build/ruby-driver-v2.19/lib/mongo/database/view.rb', line 114 def list_collections( = {}) session = client.send(:get_session, ) collections_info(session, ServerSelector.primary, ) end |