Class: Mongo::Index::View
- Inherits:
-
Object
- Object
- Mongo::Index::View
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/mongo/index/view.rb
Overview
A class representing a view of indexes.
Constant Summary collapse
- KEY =
The index key field.
'key'.freeze
- NAME =
The index name field.
'name'.freeze
- OPTIONS =
The mappings of Ruby index options to server options.
{ :background => :background, :bits => :bits, :bucket_size => :bucketSize, :default_language => :default_language, :expire_after => :expireAfterSeconds, :key => :key, :language_override => :language_override, :max => :max, :min => :min, :name => :name, :partial_filter_expression => :partialFilterExpression, :sparse => :sparse, :sphere_version => :'2dsphereIndexVersion', :storage_engine => :storageEngine, :text_version => :textIndexVersion, :unique => :unique, :version => :v, :weights => :weights }.freeze
Instance Attribute Summary collapse
-
#batch_size ⇒ Integer
readonly
Batch_size The size of the batch of results when sending the listIndexes command.
-
#collection ⇒ Collection
readonly
Collection The indexes collection.
Instance Method Summary collapse
-
#create_many(*models) ⇒ Result
Creates multiple indexes on the collection.
-
#create_one(keys, options = {}) ⇒ Result
Creates an index on the collection.
-
#drop_all ⇒ Result
Drop all indexes on the collection.
-
#drop_one(name) ⇒ Result
Drop an index by its name.
-
#each(&block) ⇒ Object
Iterate over all indexes for the collection.
-
#get(keys_or_name) ⇒ Hash
Convenience method for getting index information by a specific name or spec.
-
#initialize(collection, options = {}) ⇒ View
constructor
Create the new index view.
Constructor Details
#initialize(collection, options = {}) ⇒ View
Create the new index view.
207 208 209 210 |
# File 'lib/mongo/index/view.rb', line 207 def initialize(collection, = {}) @collection = collection @batch_size = [:batch_size] end |
Instance Attribute Details
#batch_size ⇒ Integer (readonly)
Returns batch_size The size of the batch of results when sending the listIndexes command.
30 31 32 |
# File 'lib/mongo/index/view.rb', line 30 def batch_size @batch_size end |
#collection ⇒ Collection (readonly)
Returns collection The indexes collection.
26 27 28 |
# File 'lib/mongo/index/view.rb', line 26 def collection @collection end |
Instance Method Details
#create_many(*models) ⇒ Result
On MongoDB 3.0.0 and higher, the indexes will be created in parallel on the server.
Creates multiple indexes on the collection.
148 149 150 151 152 153 154 |
# File 'lib/mongo/index/view.rb', line 148 def create_many(*models) Operation::Write::CreateIndex.new( indexes: normalize_models(models.flatten), db_name: database.name, coll_name: collection.name, ).execute(next_primary.context) end |
#create_one(keys, options = {}) ⇒ Result
Note that the options listed may be subset of those available.
Creates an index on the collection.
See the MongoDB documentation for a full list of supported options by server version.
127 128 129 |
# File 'lib/mongo/index/view.rb', line 127 def create_one(keys, = {}) create_many({ key: keys }.merge()) end |
#drop_all ⇒ Result
Drop all indexes on the collection.
92 93 94 |
# File 'lib/mongo/index/view.rb', line 92 def drop_all drop_by_name(Index::ALL) end |
#drop_one(name) ⇒ Result
Drop an index by its name.
79 80 81 82 |
# File 'lib/mongo/index/view.rb', line 79 def drop_one(name) raise Error::MultiIndexDrop.new if name == Index::ALL drop_by_name(name) end |
#each(&block) ⇒ Object
Iterate over all indexes for the collection.
184 185 186 187 188 189 190 191 |
# File 'lib/mongo/index/view.rb', line 184 def each(&block) server = next_primary(false) cursor = Cursor.new(self, send_initial_query(server), server).to_enum cursor.each do |doc| yield doc end if block_given? cursor end |