MongoDB C++ Driver legacy-1.0.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
mongo::IndexSpec Class Reference

Public Types

typedef std::vector< std::pair< std::string, IndexType > > KeyVector
 Add all components in the provided key vector to the index descriptor.
 

Public Member Functions

 IndexSpec ()
 Create a new IndexSpec.
 
IndexSpecaddKey (const StringData &field, IndexType type=kIndexTypeAscending)
 Add a new component, by default ascending, field to index.
 
IndexSpecaddKey (const BSONElement &fieldAndType)
 Add a component to this index.
 
IndexSpecaddKeys (const BSONObj &keys)
 Add all keys from the provided object to the index descriptor.
 
IndexSpecbackground (bool value=true)
 Controls whether this index should be built in the foreground or background.
 
IndexSpecunique (bool value=true)
 Set whether or not this index should enforce uniqueness.
 
IndexSpecname (const StringData &name)
 Set the name for this index.
 
IndexSpecdropDuplicates (bool value=true)
 Sets whether duplicates detected while indexing should be dropped.
 
IndexSpecdropDuplicatesDeprecated (bool value=true)
 Same as above, but doesn't emit a compiler warning on use.
 
IndexSpecsparse (bool value=true)
 Sets whether or not this index should be sparse.
 
IndexSpecexpireAfterSeconds (int value)
 Enables time-to-live semantics for this index with the specified lifetime in seconds.
 
IndexSpecversion (int value)
 Explicitly request an index of the given version.
 
IndexSpectextWeights (const BSONObj &value)
 Sets the 'weights' document for a text index.
 
IndexSpectextDefaultLanguage (const StringData &value)
 Sets the default language for a text index.
 
IndexSpectextLanguageOverride (const StringData &value)
 Sets the name of the field containing the language override in a text index.
 
IndexSpectextIndexVersion (int value)
 Sets the version of the text index to use.
 
IndexSpecgeo2DSphereIndexVersion (int value)
 Sets the version of the 2D sphere index to use.
 
IndexSpecgeo2DBits (int value)
 Sets the number of bits of precision for geohash.
 
IndexSpecgeo2DMin (double value)
 Sets the minimum value for keys in a geo2d index.
 
IndexSpecgeo2DMax (double value)
 Sets the maximum value for keys in a geo2d index.
 
IndexSpecgeoHaystackBucketSize (double value)
 Sets the bucket size for haystack indexes.
 
IndexSpecaddOption (const BSONElement &option)
 Adds another option verbatim.
 
IndexSpecaddOptions (const BSONObj &options)
 Adds the provided options verbatim.
 
std::string name () const
 Get a copy of the current name for this index.
 
BSONObj toBSON () const
 Return a BSONObj that captures the selected index keys and options.
 

Member Function Documentation

◆ addKey()

IndexSpec & mongo::IndexSpec::addKey ( const BSONElement fieldAndType)

Add a component to this index.

The field name of the element is used as the field name to index. The value of the element is the index type. This method exists to accomodate building future index types for which the enumeration value has not yet been extended.

◆ background()

IndexSpec & mongo::IndexSpec::background ( bool  value = true)

Controls whether this index should be built in the foreground or background.

By default indexes are built in the foreground.

◆ dropDuplicates()

IndexSpec & mongo::IndexSpec::dropDuplicates ( bool  value = true)

Sets whether duplicates detected while indexing should be dropped.

By default, duplicates are not dropped.

◆ expireAfterSeconds()

IndexSpec & mongo::IndexSpec::expireAfterSeconds ( int  value)

Enables time-to-live semantics for this index with the specified lifetime in seconds.

Note that the indexed field must be of type UTC datetime for this option to work correctly.

◆ geo2DSphereIndexVersion()

IndexSpec & mongo::IndexSpec::geo2DSphereIndexVersion ( int  value)

Sets the version of the 2D sphere index to use.

MongoDB 2.4 only supports version '1'. If not otherwise specified, MongoDB 2.6 defaults to version 2.

◆ name() [1/2]

std::string mongo::IndexSpec::name ( ) const

Get a copy of the current name for this index.

If a name was provided to the constructor, a copy of this name is returned. Otherwise, the current auto-generated name given the set of indexes will be returned. Note that this is a copy: subsequent changes to the indexed fields will not affect the value returned here, and you must call 'name' again to obtain the updated value.

◆ name() [2/2]

IndexSpec & mongo::IndexSpec::name ( const StringData &  name)

Set the name for this index.

If not set, a name will be automatically generated.

◆ sparse()

IndexSpec & mongo::IndexSpec::sparse ( bool  value = true)

Sets whether or not this index should be sparse.

By default, indexes are not sparse.

◆ textIndexVersion()

IndexSpec & mongo::IndexSpec::textIndexVersion ( int  value)

Sets the version of the text index to use.

MongoDB 2.4 only supports version '1'. If not otherwise specified, MongoDB 2.6 defaults to version 2.

◆ unique()

IndexSpec & mongo::IndexSpec::unique ( bool  value = true)

Set whether or not this index should enforce uniqueness.

By default, uniqueness is not enforced.

◆ version()

IndexSpec & mongo::IndexSpec::version ( int  value)

Explicitly request an index of the given version.

As of MongoDB 2.6, the only accepted values are 0 or 1. Versions 2.0 and later default to '1'. Do not set this option except in unusual circumstances.


The documentation for this class was generated from the following file: