Class | Moped::Indexes |
In: |
lib/moped/indexes.rb
|
Parent: | Object |
collection_name | [R] | @attribute [r] collection_name The collection name. @attribute [r] database The database. @attribute [r] namespace The index namespace. |
database | [R] | @attribute [r] collection_name The collection name. @attribute [r] database The database. @attribute [r] namespace The index namespace. |
namespace | [R] | @attribute [r] collection_name The collection name. @attribute [r] database The database. @attribute [r] namespace The index namespace. |
Retrive an index by its definition.
@example Get the index.
session[:users].indexes[id: 1] # => {"v"=>1, "key"=>{"_id"=>1}, "ns"=>"moped_test.users", "name"=>"_id_" }
@param [ Hash ] key The index definition.
@return [ Hash, nil ] The index with the provided key, or nil.
@since 1.0.0
Create an index unless it already exists.
@example Without options
session[:users].indexes.create(name: 1) session[:users].indexes[name: 1] # => {"v"=>1, "key"=>{"name"=>1}, "ns"=>"moped_test.users", "name"=>"name_1" }
@example With options
session[:users].indexes.create( { location: "2d", name: 1 }, { unique: true, dropDups: true } ) session[:users][location: "2d", name: 1] {"v"=>1, "key"=>{"location"=>"2d", "name"=>1}, "unique"=>true, "ns"=>"moped_test.users", "dropDups"=>true, "name"=>"location_2d_name_1"}
@param [ Hash ] key The index spec. @param [ Hash ] options The options for the index.
@return [ Hash ] The index spec.
@see www.mongodb.org/display/DOCS/Indexes#Indexes-CreationOptions
@since 1.0.0
Drop an index, or all indexes.
@example Drop all indexes
session[:users].indexes.count # => 3 # Does not drop the _id index session[:users].indexes.drop session[:users].indexes.count # => 1
@example Drop a particular index
session[:users].indexes.drop(name: 1) session[:users].indexes[name: 1] # => nil
@param [ Hash ] key The index‘s key.
@return [ Boolean ] Whether the indexes were dropped.
@since 1.0.0
Iterate over each of the indexes for the collection.
@example Iterate over the indexes.
indexes.each do |spec| #... end
@return [ Enumerator ] The enumerator.
@since 1.0.0
@yield [ Hash ] Each index for the collection.