IndexOptions

public struct IndexOptions : Codable

Options to use when creating an index for a collection.

  • Optionally tells the server to build the index in the background and not block other tasks.

    Declaration

    Swift

    public var background: Bool?
  • Optionally specifies the length in time, in seconds, for documents to remain in a collection.

    Declaration

    Swift

    public var expireAfterSeconds: Int32?
  • Optionally specify a specific name for the index outside of the default generated name. If none is provided then the name is generated in the format [field]_[direction].

    Note that if an index is created for the same key pattern with different collations, a name must be provided by the user to avoid ambiguity.

    • Example: For an index of name: 1, age: -1, the generated name would be name_1_age_-1.

    Declaration

    Swift

    public var name: String?
  • Optionally tells the index to only reference documents with the specified field in the index.

    Declaration

    Swift

    public var sparse: Bool?
  • Optionally used only in MongoDB 3.0.0 and higher. Allows users to configure the storage engine on a per-index basis when creating an index.

    Declaration

    Swift

    public var storageEngine: Document?
  • Optionally forces the index to be unique.

    Declaration

    Swift

    public var unique: Bool?
  • Optionally specifies the index version number, either 0 or 1.

    Declaration

    Swift

    public var indexVersion: Int32?
  • Optionally specifies the default language for text indexes. Is ‘english’ if none is provided.

    Declaration

    Swift

    public var defaultLanguage: String?
  • Optionally specifies the field in the document to override the language.

    Declaration

    Swift

    public var languageOverride: String?
  • Optionally provides the text index version number. MongoDB 2.4 can only support version 1. MongoDB 2.6 and higher may support version 1 or 2.

    Declaration

    Swift

    public var textIndexVersion: Int32?
  • Optionally specifies fields in the index and their corresponding weight values.

    Declaration

    Swift

    public var weights: Document?
  • Optionally specifies the 2dsphere index version number. MongoDB 2.4 can only support version 1. MongoDB 2.6 and higher may support version 1 or 2.

    Declaration

    Swift

    public var sphereIndexVersion: Int32?
  • Optionally specifies the precision of the stored geo hash in the 2d index, from 1 to 32.

    Declaration

    Swift

    public var bits: Int32?
  • max

    Optionally sets the maximum boundary for latitude and longitude in the 2d index.

    Declaration

    Swift

    public var max: Double?
  • min

    Optionally sets the minimum boundary for latitude and longitude in the index in a 2d index.

    Declaration

    Swift

    public var min: Double?
  • Optionally specifies the number of units within which to group the location values in a geo haystack index.

    Declaration

    Swift

    public var bucketSize: Int32?
  • Optionally specifies a filter for use in a partial index. Only documents that match the filter expression are included in the index. New in MongoDB 3.2.

    Declaration

    Swift

    public var partialFilterExpression: Document?
  • Optionally specifies a collation to use for the index in MongoDB 3.4 and higher. If not specified, no collation is sent and the default collation of the collection server-side is used.

    Declaration

    Swift

    public var collation: Document?
  • Convenience initializer allowing any/all parameters to be omitted.

    Declaration

    Swift

    public init(background: Bool? = nil,
                expireAfterSeconds: Int32? = nil,
                name: String? = nil,
                sparse: Bool? = nil,
                storageEngine: Document? = nil,
                unique: Bool? = nil,
                indexVersion: Int32? = nil,
                defaultLanguage: String? = nil,
                languageOverride: String? = nil,
                textIndexVersion: Int32? = nil,
                weights: Document? = nil,
                sphereIndexVersion: Int32? = nil,
                bits: Int32? = nil,
                max: Double? = nil,
                min: Double? = nil,
                bucketSize: Int32? = nil,
                partialFilterExpression: Document? = nil,
                collation: Document? = nil)