const classafMongo::Index

sys::Obj
  afMongo::Index

Represents a MongoDB index.

ASC

Source

const static Int ASC := 1

Use in key arguments to denote sort order.

DESC

Source

const static Int DESC := -1

Use in key arguments to denote sort order.

create

Source

This create(Str:Obj key, Bool? unique := (Bool?)false, Str:Obj options := ([Str:Obj])[:])

Creates this index.

key is a map of fields to index type. Values may either be the standard Mongo 1 and -1 for ascending / descending or the strings ASC / DESC.

index.create(["dateAdded" : Index.ASC])

Note that should key contain more than 1 entry, it must be ordered.

The options parameter 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.

@see http://docs.mongodb.org/manual/reference/command/createIndexes/

drop

Source

This 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 doesn't exist.

@see http://docs.mongodb.org/manual/reference/command/dropIndexes/

ensure

Source

Bool ensure(Str:Obj key, Bool? unique := (Bool?)false, Str:Obj options := ([Str:Obj])[:])

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 true if the index was (re)-created, false if nothing changed.

index.ensure(["dateAdded" : Index.ASC])

Note that should key contain more than 1 entry, it must be ordered.

The options parameter 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.

@see http://docs.mongodb.org/manual/reference/command/createIndexes/

exists

Source

Bool exists()

Returns true if this index exists.

info

Source

Str:Obj? info()

make

Source

new make(ConnectionManager conMgr, Str collectionQname, Str indexName, |This? f := null)

Creates an Index with the given details.

name

Source

const Str name

The name of this index.