Skip to content

Commit 26a423a

Browse files
authored
SWIFT-355: Make option properties mutable (#278)
* Make option properties mutable * Make cursorType a computed value * Update CodingKeys comment * Add more tests for nil cursorType cases
1 parent 75a48ba commit 26a423a

15 files changed

+189
-140
lines changed

Sources/MongoSwift/MongoClient.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import mongoc
44
/// Options to use when creating a `MongoClient`.
55
public struct ClientOptions: CodingStrategyProvider, Decodable {
66
/// Determines whether the client should retry supported write operations.
7-
public let retryWrites: Bool?
7+
public var retryWrites: Bool?
88

99
/// Indicates whether this client should be set up to enable monitoring command and server discovery and monitoring
1010
/// events.
11-
public let eventMonitoring: Bool
11+
public var eventMonitoring: Bool
1212

1313
/// Specifies a ReadConcern to use for the client. If one is not specified, the server's default read concern will
1414
/// be used.
15-
public let readConcern: ReadConcern?
15+
public var readConcern: ReadConcern?
1616

1717
/// Specifies a WriteConcern to use for the client. If one is not specified, the server's default write concern
1818
/// will be used.
19-
public let writeConcern: WriteConcern?
19+
public var writeConcern: WriteConcern?
2020

2121
// swiftlint:disable redundant_optional_initialization
2222

@@ -64,10 +64,10 @@ public struct ClientOptions: CodingStrategyProvider, Decodable {
6464
/// Options to use when listing available databases.
6565
public struct ListDatabasesOptions: Encodable {
6666
/// An optional filter for the returned databases.
67-
public let filter: Document?
67+
public var filter: Document?
6868

6969
/// Optionally indicate whether only names should be returned.
70-
public let nameOnly: Bool?
70+
public var nameOnly: Bool?
7171

7272
/// Convenience constructor for basic construction
7373
public init(filter: Document? = nil, nameOnly: Bool? = nil) {
@@ -80,27 +80,27 @@ public struct ListDatabasesOptions: Encodable {
8080
public struct DatabaseOptions: CodingStrategyProvider {
8181
/// A read concern to set on the retrieved database. If one is not specified, the database will inherit the
8282
/// client's read concern.
83-
public let readConcern: ReadConcern?
83+
public var readConcern: ReadConcern?
8484

8585
/// A read preference to set on the retrieved database. If one is not specified, the database will inherit the
8686
/// client's read preference.
87-
public let readPreference: ReadPreference?
87+
public var readPreference: ReadPreference?
8888

8989
/// A write concern to set on the retrieved database. If one is not specified, the database will inherit the
9090
/// client's write concern.
91-
public let writeConcern: WriteConcern?
91+
public var writeConcern: WriteConcern?
9292

9393
/// Specifies the `DateCodingStrategy` to use for BSON encoding/decoding operations performed by this database and
9494
/// any collections that derive from it.
95-
public let dateCodingStrategy: DateCodingStrategy?
95+
public var dateCodingStrategy: DateCodingStrategy?
9696

9797
/// Specifies the `DateCodingStrategy` to use for BSON encoding/decoding operations performed by this database and
9898
/// any collections that derive from it.
99-
public let uuidCodingStrategy: UUIDCodingStrategy?
99+
public var uuidCodingStrategy: UUIDCodingStrategy?
100100

101101
/// Specifies the `DateCodingStrategy` to use for BSON encoding/decoding operations performed by this database and
102102
/// any collections that derive from it.
103-
public let dataCodingStrategy: DataCodingStrategy?
103+
public var dataCodingStrategy: DataCodingStrategy?
104104

105105
/// Convenience initializer allowing any/all arguments to be omitted or optional.
106106
public init(readConcern: ReadConcern? = nil,

Sources/MongoSwift/MongoCollection+BulkWrite.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public class BulkWriteOperation: Operation {
423423
/// Options to use when performing a bulk write operation on a `MongoCollection`.
424424
public struct BulkWriteOptions: Codable {
425425
/// If `true`, allows the write to opt-out of document level validation.
426-
public let bypassDocumentValidation: Bool?
426+
public var bypassDocumentValidation: Bool?
427427

428428
/**
429429
* If `true` (the default), operations will be executed serially in order
@@ -432,10 +432,10 @@ public struct BulkWriteOptions: Codable {
432432
* not stop after encountering a write error (i.e. multiple errors may be
433433
* reported after all operations have been attempted).
434434
*/
435-
public let ordered: Bool
435+
public var ordered: Bool
436436

437437
/// An optional WriteConcern to use for the bulk write.
438-
public let writeConcern: WriteConcern?
438+
public var writeConcern: WriteConcern?
439439

440440
/// Convenience initializer allowing any/all parameters to be omitted or optional
441441
public init(bypassDocumentValidation: Bool? = nil, ordered: Bool? = nil, writeConcern: WriteConcern? = nil) {

Sources/MongoSwift/MongoCollection+FindAndModify.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ internal protocol FindAndModifyOptionsConvertible {
123123
/// Options to use when executing a `findOneAndDelete` command on a `MongoCollection`.
124124
public struct FindOneAndDeleteOptions: FindAndModifyOptionsConvertible, Decodable {
125125
/// Specifies a collation to use.
126-
public let collation: Document?
126+
public var collation: Document?
127127

128128
/// The maximum amount of time to allow the query to run.
129-
public let maxTimeMS: Int64?
129+
public var maxTimeMS: Int64?
130130

131131
/// Limits the fields to return for the matching document.
132-
public let projection: Document?
132+
public var projection: Document?
133133

134134
/// Determines which document the operation modifies if the query selects multiple documents.
135-
public let sort: Document?
135+
public var sort: Document?
136136

137137
/// An optional `WriteConcern` to use for the command.
138-
public let writeConcern: WriteConcern?
138+
public var writeConcern: WriteConcern?
139139

140140
internal func asFindAndModifyOptions() throws -> FindAndModifyOptions {
141141
return try FindAndModifyOptions(collation: collation,
@@ -163,28 +163,28 @@ public struct FindOneAndDeleteOptions: FindAndModifyOptionsConvertible, Decodabl
163163
/// Options to use when executing a `findOneAndReplace` command on a `MongoCollection`.
164164
public struct FindOneAndReplaceOptions: FindAndModifyOptionsConvertible, Decodable {
165165
/// If `true`, allows the write to opt-out of document level validation.
166-
public let bypassDocumentValidation: Bool?
166+
public var bypassDocumentValidation: Bool?
167167

168168
/// Specifies a collation to use.
169-
public let collation: Document?
169+
public var collation: Document?
170170

171171
/// The maximum amount of time to allow the query to run.
172-
public let maxTimeMS: Int64?
172+
public var maxTimeMS: Int64?
173173

174174
/// Limits the fields to return for the matching document.
175-
public let projection: Document?
175+
public var projection: Document?
176176

177177
/// When `ReturnDocument.After`, returns the replaced or inserted document rather than the original.
178-
public let returnDocument: ReturnDocument?
178+
public var returnDocument: ReturnDocument?
179179

180180
/// Determines which document the operation modifies if the query selects multiple documents.
181-
public let sort: Document?
181+
public var sort: Document?
182182

183183
/// When `true`, creates a new document if no document matches the query.
184-
public let upsert: Bool?
184+
public var upsert: Bool?
185185

186186
/// An optional `WriteConcern` to use for the command.
187-
public let writeConcern: WriteConcern?
187+
public var writeConcern: WriteConcern?
188188

189189
internal func asFindAndModifyOptions() throws -> FindAndModifyOptions {
190190
return try FindAndModifyOptions(bypassDocumentValidation: bypassDocumentValidation,
@@ -220,31 +220,31 @@ public struct FindOneAndReplaceOptions: FindAndModifyOptionsConvertible, Decodab
220220
/// Options to use when executing a `findOneAndUpdate` command on a `MongoCollection`.
221221
public struct FindOneAndUpdateOptions: FindAndModifyOptionsConvertible, Decodable {
222222
/// A set of filters specifying to which array elements an update should apply.
223-
public let arrayFilters: [Document]?
223+
public var arrayFilters: [Document]?
224224

225225
/// If `true`, allows the write to opt-out of document level validation.
226-
public let bypassDocumentValidation: Bool?
226+
public var bypassDocumentValidation: Bool?
227227

228228
/// Specifies a collation to use.
229-
public let collation: Document?
229+
public var collation: Document?
230230

231231
/// The maximum amount of time to allow the query to run.
232-
public let maxTimeMS: Int64?
232+
public var maxTimeMS: Int64?
233233

234234
/// Limits the fields to return for the matching document.
235-
public let projection: Document?
235+
public var projection: Document?
236236

237237
/// When`ReturnDocument.After`, returns the updated or inserted document rather than the original.
238-
public let returnDocument: ReturnDocument?
238+
public var returnDocument: ReturnDocument?
239239

240240
/// Determines which document the operation modifies if the query selects multiple documents.
241-
public let sort: Document?
241+
public var sort: Document?
242242

243243
/// When `true`, creates a new document if no document matches the query.
244-
public let upsert: Bool?
244+
public var upsert: Bool?
245245

246246
/// An optional `WriteConcern` to use for the command.
247-
public let writeConcern: WriteConcern?
247+
public var writeConcern: WriteConcern?
248248

249249
internal func asFindAndModifyOptions() throws -> FindAndModifyOptions {
250250
return try FindAndModifyOptions(arrayFilters: arrayFilters,

Sources/MongoSwift/MongoCollection+Indexes.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public struct IndexModel: Encodable {
3434
/// Options to use when creating an index for a collection.
3535
public struct IndexOptions: Codable {
3636
/// Optionally tells the server to build the index in the background and not block other tasks.
37-
public let background: Bool?
37+
public var background: Bool?
3838

3939
/// Optionally specifies the length in time, in seconds, for documents to remain in a collection.
40-
public let expireAfterSeconds: Int32?
40+
public var expireAfterSeconds: Int32?
4141

4242
/**
4343
* Optionally specify a specific name for the index outside of the default generated name. If none is provided then
@@ -51,54 +51,54 @@ public struct IndexOptions: Codable {
5151
public var name: String?
5252

5353
/// Optionally tells the index to only reference documents with the specified field in the index.
54-
public let sparse: Bool?
54+
public var sparse: Bool?
5555

5656
/// Optionally used only in MongoDB 3.0.0 and higher. Allows users to configure the storage engine on a per-index
5757
/// basis when creating an index.
58-
public let storageEngine: Document?
58+
public var storageEngine: Document?
5959

6060
/// Optionally forces the index to be unique.
61-
public let unique: Bool?
61+
public var unique: Bool?
6262

6363
/// Optionally specifies the index version number, either 0 or 1.
6464
public var indexVersion: Int32?
6565

6666
/// Optionally specifies the default language for text indexes. Is 'english' if none is provided.
67-
public let defaultLanguage: String?
67+
public var defaultLanguage: String?
6868

6969
/// Optionally specifies the field in the document to override the language.
70-
public let languageOverride: String?
70+
public var languageOverride: String?
7171

7272
/// Optionally provides the text index version number. MongoDB 2.4 can only support version 1. MongoDB 2.6 and
7373
/// higher may support version 1 or 2.
74-
public let textIndexVersion: Int32?
74+
public var textIndexVersion: Int32?
7575

7676
/// Optionally specifies fields in the index and their corresponding weight values.
77-
public let weights: Document?
77+
public var weights: Document?
7878

7979
/// Optionally specifies the 2dsphere index version number. MongoDB 2.4 can only support version 1. MongoDB 2.6 and
8080
/// higher may support version 1 or 2.
81-
public let sphereIndexVersion: Int32?
81+
public var sphereIndexVersion: Int32?
8282

8383
/// Optionally specifies the precision of the stored geo hash in the 2d index, from 1 to 32.
84-
public let bits: Int32?
84+
public var bits: Int32?
8585

8686
/// Optionally sets the maximum boundary for latitude and longitude in the 2d index.
87-
public let max: Double?
87+
public var max: Double?
8888

8989
/// Optionally sets the minimum boundary for latitude and longitude in the index in a 2d index.
90-
public let min: Double?
90+
public var min: Double?
9191

9292
/// Optionally specifies the number of units within which to group the location values in a geo haystack index.
93-
public let bucketSize: Int32?
93+
public var bucketSize: Int32?
9494

9595
/// Optionally specifies a filter for use in a partial index. Only documents that match the filter expression are
9696
/// included in the index. New in MongoDB 3.2.
97-
public let partialFilterExpression: Document?
97+
public var partialFilterExpression: Document?
9898

9999
/// Optionally specifies a collation to use for the index in MongoDB 3.4 and higher. If not specified, no collation
100100
/// is sent and the default collation of the collection server-side is used.
101-
public let collation: Document?
101+
public var collation: Document?
102102

103103
/// Convenience initializer allowing any/all parameters to be omitted.
104104
public init(background: Bool? = nil,

0 commit comments

Comments
 (0)