Table of Contents

Class IndexKeysBuilder

Namespace
MongoDB.Driver.Builders
Assembly
MongoDB.Driver.Legacy.dll

A builder for specifying the keys for an index.

[Serializable]
[BsonSerializer(typeof(IndexKeysBuilder.Serializer))]
public class IndexKeysBuilder : BuilderBase, IConvertibleToBsonDocument, IMongoIndexKeys
Inheritance
IndexKeysBuilder
Implements
Inherited Members
Extension Methods

Constructors

IndexKeysBuilder()

Initializes a new instance of the IndexKeysBuilder class.

public IndexKeysBuilder()

Methods

Ascending(params string[])

Sets one or more key names to index in ascending order.

public IndexKeysBuilder Ascending(params string[] names)

Parameters

names string[]

One or more key names.

Returns

IndexKeysBuilder

The builder (so method calls can be chained).

Descending(params string[])

Sets one or more key names to index in descending order.

public IndexKeysBuilder Descending(params string[] names)

Parameters

names string[]

One or more key names.

Returns

IndexKeysBuilder

The builder (so method calls can be chained).

GeoSpatial(string)

Sets the key name to create a geospatial index on.

public IndexKeysBuilder GeoSpatial(string name)

Parameters

name string

The key name.

Returns

IndexKeysBuilder

The builder (so method calls can be chained).

GeoSpatialHaystack(string)

Sets the key name to create a geospatial haystack index on.

[Obsolete("GeoHaystack indexes were deprecated in server version 4.4.")]
public IndexKeysBuilder GeoSpatialHaystack(string name)

Parameters

name string

The key name.

Returns

IndexKeysBuilder

The builder (so method calls can be chained).

GeoSpatialHaystack(string, string)

Sets the key name and additional field name to create a geospatial haystack index on.

[Obsolete("GeoHaystack indexes were deprecated in server version 4.4.")]
public IndexKeysBuilder GeoSpatialHaystack(string name, string additionalName)

Parameters

name string

The key name.

additionalName string

The name of an additional field to index.

Returns

IndexKeysBuilder

The builder (so method calls can be chained).

GeoSpatialSpherical(string)

Sets the key name to create a spherical geospatial index on.

public IndexKeysBuilder GeoSpatialSpherical(string name)

Parameters

name string

The key name.

Returns

IndexKeysBuilder

The builder (so method calls can be chained).

Hashed(string)

Sets the key name to create a hashed index on.

public IndexKeysBuilder Hashed(string name)

Parameters

name string

The key name.

Returns

IndexKeysBuilder

The builder (so method calls can be chained).

Text(params string[])

Sets one or more key names to include in the text index.

public IndexKeysBuilder Text(params string[] names)

Parameters

names string[]

List of key names to include in the text index.

Returns

IndexKeysBuilder

The builder (so method calls can be chained).

TextAll()

Create a text index that indexes all text fields of a document.

public IndexKeysBuilder TextAll()

Returns

IndexKeysBuilder

The builder (so method calls can be chained).

ToBsonDocument()

Returns the result of the builder as a BsonDocument.

public override BsonDocument ToBsonDocument()

Returns

BsonDocument

A BsonDocument.

Wildcard(string)

Sets a wildcard key to the index. The method doesn't expect to specify a wildcard key explicitly.

public IndexKeysBuilder Wildcard(string name = null)

Parameters

name string

The wildcard key name. If the wildcard name is empty, the generated key will be All field paths, otherwise A single field path.

Returns

IndexKeysBuilder

The builder (so method calls can be chained).