const classafMongo::MongoIdx
sys::Obj afMongo::MongoIdx
Represents a MongoDB index.
- ASC
const static Int ASC := 1
Use in
key
arguments to denote field sort order.- DESC
const static Int DESC := -1
Use in
key
arguments to denote field sort order.- TEXT
const static Str TEXT := "text"
Use in
key
arguments to denote a text index on the field.- coll
MongoColl coll()
Creates a
MongoColl
instance of the associated Collection.- collName
const Str collName
The simple name of the collection.
- connMgr
const MongoConnMgr connMgr
The underlying connection manager.
- create
Str:Obj? create(Str:Obj key, Bool unique := false, |MongoCmd? optsFn := null)
Creates this index.
key
is a map of fields to index type. If it contains more than 1 entry, it must be ordered.Values should be the standard Mongo
1
and-1
for 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
MongoDb
instance of the associated DB.- dbName
const Str dbName
The name of the database.
- drop
Void drop(Bool force := false)
Drops this index, but only if it exists.
If
force
istrue
then 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
true
if the index was (re)-created,false
if 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
true
if this index exists.- info
Returns index info.
Returns
null
if 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 name
The simple name of this index.