orlandos-nl / MongoKitten

Native MongoDB driver for Swift, written in Swift

Home Page:https://orlandos.nl/docs/mongokitten/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create unique index with multiple fields

JohnCoates opened this issue · comments

Is your feature request related to a problem? Please describe.

Is it currently possible to build a unique index with multiple fields? I looked at the following code but it didn't look like I could do that.

public func UniqueIndex<M, T>(
named name: String,
field: QuerySubject<M, T>,
order: Sorting.Order = .ascending
) -> _MongoIndex {
UniqueIndex(named: name, field: field.path.string, order: order)
}

Describe the solution you'd like
Would be great to add a unique index with multiple fields.

Describe alternatives you've considered
None.

Additional context
N/A

Hey, thanks for highlighting this! MongoKitten 7 has a couple of helpers already, but I don't think I'll add overrides for each and every possible scenario. However, I propose adding an override on SortedIndex that accepts multiple fields, which you can then mark as unique using the .unique() function on that index.

That sounds like a good solution.

fixed in 7.2.14