const classafMongo::Index
sys::Obj afMongo::Index
Represents a MongoDB index.
- ASC
const static Int ASC := 1Use in
keyarguments to denote field sort order.- DESC
const static Int DESC := -1Use in
keyarguments to denote field sort order.- TEXT
const static Str TEXT := "text"Use in
keyarguments to denote a text index on the field.- create
This create(Str:Obj key, Bool? unique := false, Str:Obj options := [:])Creates this index.
keyis a map of fields to index type. Values may either be the standard Mongo1and-1for ascending / descending, the stringsASC/DESC, or the stringTEXT.index.create(["dateAdded" : Index.ASC])
Note that should
keycontain more than 1 entry, it must be ordered.The
optionsparameter is merged with the Mongo command. Options are numerous (see the MongoDB documentation for details) but common options are:Name
Type
Desc
background
Bool
Builds the index in the background so it does not block other database activities. Defaults to
false.sparse
Bool
Only reference documents with the specified field. Uses less space but behave differently in sorts. Defaults to
false.expireAfterSeconds
Int
Specifies a Time To Live (TTL) in seconds that controls how long documents are retained.
weights
Map
Specifies the relative weights of fields to use in text searching. See Control Search Results with Weights.
default_language
Str
The language used to create text indexes. See Supported Text Search Languages. Defaults to
english.@see http://docs.mongodb.org/manual/reference/command/createIndexes/
- drop
This drop(Bool force := false)Drops this index, but only if it exists.
If
forceistruethen the index is dropped regardless. Note this may result in an error if the index doesn't exist.@see http://docs.mongodb.org/manual/reference/command/dropIndexes/
- ensure
Bool ensure(Str:Obj key, Bool? unique := false, Str:Obj options := [:])Ensures this index exists. If the index does not exist, it is created. If it exists but with a different key / options, it is dropped and re-created.
Returns
trueif the index was (re)-created,falseif nothing changed.index.ensure(["dateAdded" : Index.ASC])
Note that should
keycontain more than 1 entry, it must be ordered.The
optionsparameter is merged with the Mongo command. Options are numerous (see the MongoDB documentation for details) but common options are:Name
Type
Desc
background
Bool
Builds the index in the background so it does not block other database activities.
sparse
Bool
Only reference documents with the specified field. Uses less space but behave differently in sorts.
expireAfterSeconds
Int
Specifies a Time To Live (TTL) in seconds that controls how long documents are retained.
weights
Map
Specifies the relative weights of fields to use in text searching. See Control Search Results with Weights.
default_language
Str
The language used to create text indexes. See Text Search Languages for a list of valid options. Defaults to
english.@see http://docs.mongodb.org/manual/reference/command/createIndexes/
- exists
Bool exists()Returns
trueif this index exists.- info
Returns index info.
Returns
nullif index does not exist.@see http://docs.mongodb.org/manual/reference/method/db.collection.getIndexes/
- make
new make(ConnectionManager conMgr, Str collectionQname, Str indexName, |This? f := null)Creates an
Indexwith the given details.- name
const Str nameThe name of this index.