const classafMongo::MongoIdx
sys::Obj afMongo::MongoIdx
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.- coll
MongoColl coll()Creates a
MongoCollinstance of the associated Collection.- collName
const Str collNameThe simple name of the collection.
- connMgr
const MongoConnMgr connMgrThe underlying connection manager.
- create
Str:Obj? create(Str:Obj key, Bool unique := false, |MongoCmd? optsFn := null)Creates this index.
keyis a map of fields to index type. If it contains more than 1 entry, it must be ordered.Values should be the standard Mongo
1and-1for ascending / descending, or the stringTEXT.index.create([ "dateAdded" : MongoIdx.DESC, "name" : MongoIdx.ASC, ], false) { it->background = true// build in backgroundit->expireAfterSeconds = 60// time in secs}Text indexes need to specify weights for each field.
index.create([ "boringText" : MongoIdx.TEXT, "importantText" : MongoIdx.TEXT, ], false) { it->default_language = "english",// optionalit->collation = [...],// optionalit->weights = [ "boringText" : 5, "importantText" : 15// is x3 more important than boring!] }Note that Text Indexes are NOT part of the Mongo Stable API.
@see https://www.mongodb.com/docs/manual/reference/command/createIndexes/ @see https://www.mongodb.com/docs/manual/core/index-text/
- db
MongoDb db()Creates an
MongoDbinstance of the associated DB.- dbName
const Str dbNameThe name of the database.
- drop
Void 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 does not exist.@see https://www.mongodb.com/docs/manual/reference/command/dropIndexes/
- ensure
Bool ensure(Str:Obj key, Bool unique := false, |MongoCmd? optsFn := null)Ensures this index exists. Returns
trueif the index was (re)-created,falseif nothing changed.If the index does not exist, it is created.
If does exist, but with a different key, it is dropped and re-created. (Options are not checked.)
- exists
Bool exists()Returns
trueif this index exists.- info
Returns index info.
Returns
nullif index does not exist.@see https://www.mongodb.com/docs/manual/reference/command/listIndexes/
- make
new make(MongoConnMgr connMgr, Str idxName, Str colName, Str? dbName := null)- name
const Str nameThe simple name of this index.