CollectionOptions
public struct CollectionOptions : Sendable
Configuration options for opening or creating a collection.
CollectionOptions lets you specify the document id field, an optional
partition key for shard routing, and additional fields to index for
query performance.
Note
TheidField and partitionKey are frozen at collection creation.
Changing them after data exists would make existing records unreadable.
indexedFields can be extended across opens.
-
The JSON field (dot paths allowed) that uniquely identifies a document.
An index on this field is always maintained —
get,update,delete, andpatchare O(log n) point operations through it.Changing this after creation is not supported.
Default:
"id".Declaration
Swift
public var idField: String -
An optional JSON field used to route documents into shard files.
When set, documents with the same partition key value are stored in the same physical shard file. This enables partition-scoped scans that only touch one shard instead of all shards. The partition key also affects the query planner: an equality predicate on the partition key triggers a partition scan instead of a full scan.
Default:
nil(all documents go into the"default"shard).Declaration
Swift
public var partitionKey: String? -
Additional fields to index for query performance.
Each field in this list gets an
OrderedIndexthat supports point lookups, range queries,INqueries, and sorting. The id field is always indexed automatically and does not need to be listed here.Fields can be added across opens — new indexes are populated by scanning all shards. Removing a field drops its index.
Default:
[].Declaration
Swift
public var indexedFields: [String] -
Creates collection options for opening or creating a collection.
Declaration
Swift
public init( idField: String = "id", partitionKey: String? = nil, indexedFields: [String] = [] )Parameters
idFieldDocument id field name (default
"id").partitionKeyOptional partition key field for sharding.
indexedFieldsAdditional indexed fields for queries.
View on GitHub