const classafMongo::MongoIdx

sys::Obj
  afMongo::MongoIdx

Represents a MongoDB index.

ASC

Source

const static Int ASC := 1

Use in key arguments to denote field sort order.

DESC

Source

const static Int DESC := -1

Use in key arguments to denote field sort order.

TEXT

Source

const static Str TEXT := "text"

Use in key arguments to denote a text index on the field.

coll

Source

MongoColl coll()

Creates a MongoColl instance of the associated Collection.

collName

Source

const Str collName

The simple name of the collection.

connMgr

Source

const MongoConnMgr connMgr

The underlying connection manager.

create

Source

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 string TEXT.

index.create([
  "dateAdded" : MongoIdx.DESC,
  "name"      : MongoIdx.ASC,
], false) {
  it->background         = true   // build in background
  it->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",  // optional
  it->collation        = [...],      // optional 
  it->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

Source

MongoDb db()

Creates an MongoDb instance of the associated DB.

dbName

Source

const Str dbName

The name of the database.

drop

Source

Void drop(Bool force := false)

Drops this index, but only if it exists.

If force is true 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

Source

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

Source

Bool exists()

Returns true if this index exists.

info

Source

[Str:Obj?]? info()

Returns index info.

Returns null if index does not exist.

@see https://www.mongodb.com/docs/manual/reference/command/listIndexes/

make

Source

new make(MongoConnMgr connMgr, Str idxName, Str colName, Str? dbName := null)

name

Source

const Str name

The simple name of this index.