Skip to main content

Function: Index()

Call Signature​

Index(nameOrOptions?, options?): PropertyDecorator

Defined in: service-core/src/decorators/PersistenceDecorators.ts:220

Declares a database index.

When applied to a property, creates an index on that single property:

@Index() // unnamed index
@Index("myName") // named index
@Index({ unique: true }) // unnamed unique index
@Index("myName", { unique: true }) // named unique index

When applied to a class, creates a compound index across the given properties:

@Index(["firstName", "lastName"])
@Index("fullName", ["firstName", "lastName"], { unique: true })

Parameters​

nameOrOptions?​

string | IndexOptions

options?​

IndexOptions

Returns​

PropertyDecorator

Call Signature​

Index(fields, options?): ClassDecorator

Defined in: service-core/src/decorators/PersistenceDecorators.ts:221

Declares a database index.

When applied to a property, creates an index on that single property:

@Index() // unnamed index
@Index("myName") // named index
@Index({ unique: true }) // unnamed unique index
@Index("myName", { unique: true }) // named unique index

When applied to a class, creates a compound index across the given properties:

@Index(["firstName", "lastName"])
@Index("fullName", ["firstName", "lastName"], { unique: true })

Parameters​

fields​

string[]

options?​

IndexOptions

Returns​

ClassDecorator

Call Signature​

Index(name, fields, options?): ClassDecorator

Defined in: service-core/src/decorators/PersistenceDecorators.ts:222

Declares a database index.

When applied to a property, creates an index on that single property:

@Index() // unnamed index
@Index("myName") // named index
@Index({ unique: true }) // unnamed unique index
@Index("myName", { unique: true }) // named unique index

When applied to a class, creates a compound index across the given properties:

@Index(["firstName", "lastName"])
@Index("fullName", ["firstName", "lastName"], { unique: true })

Parameters​

name​

string

fields​

string[]

options?​

IndexOptions

Returns​

ClassDecorator