diff --git a/Gemfile.lock b/Gemfile.lock index 204ea00..34bb549 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,4 +9,4 @@ DEPENDENCIES bundler BUNDLED WITH - 1.17.2 + 2.0.1 diff --git a/Package.swift b/Package.swift index 5abb5d3..efcf6cd 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/vapor/core.git", .upToNextMajor(from: "3.8.1")), .package(url: "https://github.com/vapor/fluent.git", .upToNextMajor(from: "3.2.0")), - .package(url: "https://github.com/mongodb/mongo-swift-driver.git", .upToNextMinor(from: "0.1.0")) + .package(url: "https://github.com/mongodb/mongo-swift-driver.git", .upToNextMinor(from: "0.1.3")) ], targets: [ .target(name: "FluentMongo", dependencies: ["Async", "Fluent", "MongoSwift"]), diff --git a/Sources/FluentMongo/FluentMongoProvider.swift b/Sources/FluentMongo/FluentMongoProvider.swift index e5cdf55..8d082f2 100755 --- a/Sources/FluentMongo/FluentMongoProvider.swift +++ b/Sources/FluentMongo/FluentMongoProvider.swift @@ -15,7 +15,6 @@ public final class FluentMongoProvider: Provider { public init() {} public func register(_ services: inout Services) throws { - MongoSwift.initialize() try services.register(FluentProvider()) try services.register(DatabaseKitProvider()) services.register(MongoDatabaseConfig.self) diff --git a/Sources/FluentMongo/IndexBuilder.swift b/Sources/FluentMongo/IndexBuilder.swift index 34ad3b1..75b7c5f 100644 --- a/Sources/FluentMongo/IndexBuilder.swift +++ b/Sources/FluentMongo/IndexBuilder.swift @@ -49,108 +49,32 @@ extension IndexBuilder { } public func background(_ value: Bool) -> IndexBuilder { - let previous = self.index.options - let options = IndexOptions( - background: value, - expireAfter: previous?.expireAfter, - name: previous?.name, - sparse: previous?.sparse, - storageEngine: previous?.storageEngine, - unique: previous?.unique, - version: previous?.version, - defaultLanguage: previous?.defaultLanguage, - languageOverride: previous?.defaultLanguage, - textVersion: previous?.textVersion, - weights: previous?.weights, - sphereVersion: previous?.sphereVersion, - bits: previous?.bits, - max: previous?.max, - min: previous?.min, - bucketSize: previous?.bucketSize, - partialFilterExpression: previous?.partialFilterExpression, - collation: previous?.collation - ) + var options = self.index.options ?? IndexOptions() + options.background = value self.index = IndexModel(keys: self.index.keys, options: options) return self } public func expireAfter(_ value: Int32) -> IndexBuilder { - let previous = self.index.options - let options = IndexOptions( - background: previous?.background, - expireAfter: value, - name: previous?.name, - sparse: previous?.sparse, - storageEngine: previous?.storageEngine, - unique: previous?.unique, - version: previous?.version, - defaultLanguage: previous?.defaultLanguage, - languageOverride: previous?.defaultLanguage, - textVersion: previous?.textVersion, - weights: previous?.weights, - sphereVersion: previous?.sphereVersion, - bits: previous?.bits, - max: previous?.max, - min: previous?.min, - bucketSize: previous?.bucketSize, - partialFilterExpression: previous?.partialFilterExpression, - collation: previous?.collation - ) + var options = self.index.options ?? IndexOptions() + options.expireAfterSeconds = value self.index = IndexModel(keys: self.index.keys, options: options) return self } public func name(_ value: String) -> IndexBuilder { - let previous = self.index.options - let options = IndexOptions( - background: previous?.background, - expireAfter: previous?.expireAfter, - name: value, - sparse: previous?.sparse, - storageEngine: previous?.storageEngine, - unique: previous?.unique, - version: previous?.version, - defaultLanguage: previous?.defaultLanguage, - languageOverride: previous?.defaultLanguage, - textVersion: previous?.textVersion, - weights: previous?.weights, - sphereVersion: previous?.sphereVersion, - bits: previous?.bits, - max: previous?.max, - min: previous?.min, - bucketSize: previous?.bucketSize, - partialFilterExpression: previous?.partialFilterExpression, - collation: previous?.collation - ) + var options = self.index.options ?? IndexOptions() + options.name = value self.index = IndexModel(keys: self.index.keys, options: options) return self } public func unique(_ value: Bool) -> IndexBuilder { - let previous = self.index.options - let options = IndexOptions( - background: previous?.background, - expireAfter: previous?.expireAfter, - name: previous?.name, - sparse: previous?.sparse, - storageEngine: previous?.storageEngine, - unique: value, - version: previous?.version, - defaultLanguage: previous?.defaultLanguage, - languageOverride: previous?.defaultLanguage, - textVersion: previous?.textVersion, - weights: previous?.weights, - sphereVersion: previous?.sphereVersion, - bits: previous?.bits, - max: previous?.max, - min: previous?.min, - bucketSize: previous?.bucketSize, - partialFilterExpression: previous?.partialFilterExpression, - collation: previous?.collation - ) + var options = self.index.options ?? IndexOptions() + options.unique = value self.index = IndexModel(keys: self.index.keys, options: options) return self