Table of Contents

Class Index<T>

Namespace
MongoDB.Entities
Assembly
MongoDB.Entities.dll

Represents an index creation command

TIP: Define the keys first with .Key() method and finally call the .InitAsync() method.

public class Index<T> where T : IEntity

Type Parameters

T

Any class that implements IEntity

Inheritance
Index<T>
Inherited Members

Constructors

Index(DB)

Represents an index creation command

TIP: Define the keys first with .Key() method and finally call the .InitAsync() method.

public Index(DB db)

Parameters

db DB

Methods

CreateAsync(CancellationToken)

Call this method to finalize defining the index after setting the index keys and options.

public Task<string> CreateAsync(CancellationToken cancellation = default)

Parameters

cancellation CancellationToken

An optional cancellation token

Returns

Task<string>

The name of the created index

DropAllAsync(CancellationToken)

Drops all indexes for this entity type

public Task DropAllAsync(CancellationToken cancellation = default)

Parameters

cancellation CancellationToken

An optional cancellation token

Returns

Task

DropAsync(string, CancellationToken)

Drops an index by name for this entity type

public Task DropAsync(string name, CancellationToken cancellation = default)

Parameters

name string

The name of the index to drop

cancellation CancellationToken

An optional cancellation token

Returns

Task

Key(Expression<Func<T, object?>>, KeyType)

Adds a key definition to the index

TIP: At least one key definition is required

public Index<T> Key(Expression<Func<T, object?>> propertyToIndex, KeyType type)

Parameters

propertyToIndex Expression<Func<T, object>>

x => x.PropertyName

type KeyType

The type of the key

Returns

Index<T>

Option(Action<CreateIndexOptions<T>>)

Set the options for this index definition

TIP: Setting options is not required.

public Index<T> Option(Action<CreateIndexOptions<T>> option)

Parameters

option Action<CreateIndexOptions<T>>

x => x.OptionName = OptionValue

Returns

Index<T>