Class: Mongo::Database::View
- Inherits:
-
Object
- Object
- Mongo::Database::View
- Extended by:
- Forwardable
- Includes:
- Enumerable, Cursor::NonTailable, CursorHost, Retryable
- Defined in:
- 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.
-
#operation_timeout_ms ⇒ Integer | nil | The timeout_ms value that was passed as an option to the view.
readonly
private
Integer | nil | The timeout_ms value that was passed as an option to the view.
Attributes included from CursorHost
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, options = {}) ⇒ View
constructor
Create the new database view.
-
#list_collections(options = {}) ⇒ Array<Hash>
Get info on all the collections in the database.
-
#operation_timeouts(opts = {}) ⇒ Hash
private
Timeout_ms value set on the operation level (if any).
-
#timeout_ms ⇒ Integer | nil
The timeout_ms value to use for this operation; either specified as an option to the view, or inherited from the database.
Methods included from Cursor::NonTailable
Methods included from CursorHost
Methods included from Retryable
#read_worker, #select_server, #with_overload_retry, #write_worker
Constructor Details
#initialize(database, options = {}) ⇒ View
Create the new database view.
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/mongo/database/view.rb', line 143 def initialize(database, = {}) @database = database @operation_timeout_ms = .delete(:timeout_ms) validate_timeout_mode!() @batch_size = nil @limit = nil @collection = @database[Database::COMMAND] end |
Instance Attribute Details
#batch_size ⇒ Integer (readonly)
Returns batch_size The size of the batch of results when sending the listCollections command.
38 39 40 |
# File 'lib/mongo/database/view.rb', line 38 def batch_size @batch_size end |
#collection ⇒ Collection (readonly)
Returns collection The command collection.
44 45 46 |
# File 'lib/mongo/database/view.rb', line 44 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.
155 156 157 |
# File 'lib/mongo/database/view.rb', line 155 def database @database end |
#limit ⇒ Integer (readonly)
Returns limit The limit when sending a command.
41 42 43 |
# File 'lib/mongo/database/view.rb', line 41 def limit @limit end |
#operation_timeout_ms ⇒ Integer | nil | The timeout_ms value that was passed as an option to the view. (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.
Returns Integer | nil | The timeout_ms value that was passed as an option to the view.
161 162 163 |
# File 'lib/mongo/database/view.rb', line 161 def operation_timeout_ms @operation_timeout_ms 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.
177 178 179 |
# File 'lib/mongo/database/view.rb', line 177 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.
See https://mongodb.com/docs/manual/reference/command/listCollections/
for more information and usage.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/mongo/database/view.rb', line 75 def collection_names( = {}) @batch_size = [:batch_size] session = client.get_session() context = Operation::Context.new( client: client, session: session, operation_timeouts: operation_timeouts() ) cursor = read_with_retry_cursor(session, ServerSelector.primary, self, context: context) do |server| send_initial_query(server, session, context, .merge(name_only: true)) end cursor.map { |info| info['name'] } .reject { |name| name.start_with?('system.') || name.include?('$') } 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.
121 122 123 124 |
# File 'lib/mongo/database/view.rb', line 121 def list_collections( = {}) session = client.get_session() collections_info(session, ServerSelector.primary, ) end |
#operation_timeouts(opts = {}) ⇒ Hash
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.
Returns timeout_ms value set on the operation level (if any).
192 193 194 195 196 197 198 199 200 |
# File 'lib/mongo/database/view.rb', line 192 def operation_timeouts(opts = {}) {}.tap do |result| if opts[:timeout_ms] || operation_timeout_ms result[:operation_timeout_ms] = opts.delete(:timeout_ms) || operation_timeout_ms else result[:inherited_timeout_ms] = database.timeout_ms end end end |
#timeout_ms ⇒ Integer | nil
The timeout_ms value to use for this operation; either specified as an option to the view, or inherited from the database.
185 186 187 |
# File 'lib/mongo/database/view.rb', line 185 def timeout_ms operation_timeout_ms || database.timeout_ms end |