Skip to content

Commit

Permalink
Merge pull request #240 from OpenKitten/feature/create-index-update
Browse files Browse the repository at this point in the history
Add a new createIndexes function for more flexibility and customization
  • Loading branch information
Andrewangeta authored May 4, 2020
2 parents edd525b + a7b9f6d commit f2cf1a0
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ extension MongoCollection {
/// Creates a new index by this name. If the index already exists, a new one is _not_ created.
/// - returns: A future indicating success or failure.
public func createIndex(named name: String, keys: Document) -> EventLoopFuture<Void> {
return createIndexes([CreateIndexes.Index(named: name, keys: keys)])
}

/// Create 1 or more indexes on the collection.
/// - Parameter indexes: A collection of indexes to be created.
/// - Returns: A future indicating success or failure.
public func createIndexes(_ indexes: [CreateIndexes.Index]) -> EventLoopFuture<Void> {
guard transaction == nil else {
return makeTransactionError()
}
Expand All @@ -13,7 +20,7 @@ extension MongoCollection {
return connection.executeCodable(
CreateIndexes(
collection: self.name,
indexes: [CreateIndexes.Index(named: name, keys: keys)]
indexes: indexes
),
namespace: self.database.commandNamespace,
in: self.transaction,
Expand Down

0 comments on commit f2cf1a0

Please sign in to comment.