Skip to content

Commit 7ef35aa

Browse files
authored
SWIFT-1385 Add support for the comment field to all helpers/options (#760)
1 parent 3eb642c commit 7ef35aa

File tree

55 files changed

+5880
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+5880
-58
lines changed

Sources/MongoSwift/AsyncAwait/MongoCollection+Indexes+AsyncAwait.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,28 +181,36 @@ extension MongoCollection {
181181
* Retrieves a list of the indexes currently on this collection.
182182
*
183183
* - Parameters:
184+
* - options: Optional `ListIndexesOptions` to use for the command
184185
* - session: Optional `ClientSession` to use when executing this command.
185186
*
186187
* - Returns: A `MongoCursor` over the `IndexModel`s.
187188
*
188189
* - Throws: `MongoError.LogicError` if the provided session is inactive.
189190
*/
190-
public func listIndexes(session: ClientSession? = nil) async throws -> MongoCursor<IndexModel> {
191-
try await self.listIndexes(session: session).get()
191+
public func listIndexes(
192+
options: ListIndexesOptions? = nil,
193+
session: ClientSession? = nil
194+
) async throws -> MongoCursor<IndexModel> {
195+
try await self.listIndexes(options: options, session: session).get()
192196
}
193197

194198
/**
195199
* Retrieves a list of names of the indexes currently on this collection.
196200
*
197201
* - Parameters:
202+
* - options: Optional `ListIndexesOptions` to use for the command
198203
* - session: Optional `ClientSession` to use when executing this command.
199204
*
200205
* - Returns: A `MongoCursor` over the index names.
201206
*
202207
* - Throws: `MongoError.LogicError` if the provided session is inactive.
203208
*/
204-
public func listIndexNames(session: ClientSession? = nil) async throws -> [String] {
205-
try await self.listIndexNames(session: session).get()
209+
public func listIndexNames(
210+
options: ListIndexesOptions? = nil,
211+
session: ClientSession? = nil
212+
) async throws -> [String] {
213+
try await self.listIndexNames(options: options, session: session).get()
206214
}
207215
}
208216
#endif

Sources/MongoSwift/ChangeStreamOptions.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public struct ChangeStreamOptions: Codable {
2626
/// - SeeAlso: https://docs.mongodb.com/manual/reference/command/aggregate
2727
public var collation: BSONDocument?
2828

29+
/// A comment to help trace the operation through the database profiler,
30+
/// currentOp and logs. Can be any valid BSON type for server versions
31+
/// 4.4 and above but older server versions only support string comments
32+
/// (non-string types cause server-side errors). The default is to not send a value.
33+
public var comment: BSON?
34+
2935
/**
3036
* Indicates how the `fullDocument` field of a change stream document should be filled out by the server.
3137
* By default (indicated by a nil value for this option), the `fullDocument` field in the change stream document
@@ -66,6 +72,7 @@ public struct ChangeStreamOptions: Codable {
6672
public init(
6773
batchSize: Int? = nil,
6874
collation: BSONDocument? = nil,
75+
comment: BSON? = nil,
6976
fullDocument: FullDocument? = nil,
7077
maxAwaitTimeMS: Int? = nil,
7178
resumeAfter: ResumeToken? = nil,
@@ -74,6 +81,7 @@ public struct ChangeStreamOptions: Codable {
7481
) {
7582
self.batchSize = batchSize
7683
self.collation = collation
84+
self.comment = comment
7785
self.fullDocument = fullDocument
7886
self.maxAwaitTimeMS = maxAwaitTimeMS
7987
self.resumeAfter = resumeAfter

Sources/MongoSwift/MongoCollection+BulkWrite.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ public struct DeleteModelOptions: Codable {
165165
public var hint: IndexHint?
166166

167167
/// Initializer allowing any/all options to be omitted or optional.
168-
public init(collation: BSONDocument? = nil, hint: IndexHint? = nil) {
168+
public init(
169+
collation: BSONDocument? = nil,
170+
hint: IndexHint? = nil
171+
) {
169172
self.collation = collation
170173
self.hint = hint
171174
}
@@ -175,13 +178,19 @@ public struct DeleteModelOptions: Codable {
175178
public struct ReplaceOneModelOptions: Codable {
176179
/// The collation to use.
177180
public var collation: BSONDocument?
181+
178182
/// A document or string that specifies the index to use to support the query. Only supported in server 4.2+.
179183
public var hint: IndexHint?
184+
180185
/// When `true`, creates a new document if no document matches the query.
181186
public var upsert: Bool?
182187

183188
/// Initializer allowing any/all options to be omitted or optional.
184-
public init(collation: BSONDocument? = nil, hint: IndexHint? = nil, upsert: Bool? = nil) {
189+
public init(
190+
collation: BSONDocument? = nil,
191+
hint: IndexHint? = nil,
192+
upsert: Bool? = nil
193+
) {
185194
self.collation = collation
186195
self.hint = hint
187196
self.upsert = upsert
@@ -194,6 +203,7 @@ public struct UpdateModelOptions: Codable {
194203
public var arrayFilters: [BSONDocument]?
195204
/// The collation to use.
196205
public var collation: BSONDocument?
206+
197207
/// A document or string that specifies the index to use to support the query. Only supported in server 4.2+.
198208
public var hint: IndexHint?
199209
/// When `true`, creates a new document if no document matches the query.
@@ -307,6 +317,12 @@ public struct BulkWriteOptions: Codable {
307317
/// If `true`, allows the write to opt-out of document level validation.
308318
public var bypassDocumentValidation: Bool?
309319

320+
/// A comment to help trace the operation through the database profiler,
321+
/// currentOp and logs. Can be any valid BSON type for server versions
322+
/// 4.4 and above but older server versions only support string comments
323+
/// (non-string types cause server-side errors). The default is to not send a value.
324+
public var comment: BSON?
325+
310326
/**
311327
* If `true` (the default), operations will be executed serially in order
312328
* and a write error will abort execution of the entire bulk write. If
@@ -320,8 +336,14 @@ public struct BulkWriteOptions: Codable {
320336
public var writeConcern: WriteConcern?
321337

322338
/// Convenience initializer allowing any/all parameters to be omitted or optional
323-
public init(bypassDocumentValidation: Bool? = nil, ordered: Bool? = nil, writeConcern: WriteConcern? = nil) {
339+
public init(
340+
bypassDocumentValidation: Bool? = nil,
341+
comment: BSON? = nil,
342+
ordered: Bool? = nil,
343+
writeConcern: WriteConcern? = nil
344+
) {
324345
self.bypassDocumentValidation = bypassDocumentValidation
346+
self.comment = comment
325347
self.ordered = ordered ?? true
326348
self.writeConcern = writeConcern
327349
}
@@ -333,18 +355,20 @@ public struct BulkWriteOptions: Codable {
333355
}
334356

335357
self.bypassDocumentValidation = options.bypassDocumentValidation
358+
self.comment = options.comment
336359
self.ordered = options.ordered
337360
self.writeConcern = options.writeConcern
338361
}
339362

340363
private enum CodingKeys: String, CodingKey {
341-
case bypassDocumentValidation, ordered, writeConcern
364+
case bypassDocumentValidation, comment, ordered, writeConcern
342365
}
343366

344367
// A manual implementation is required to enforce a default value for ordered without making it optional.
345368
public init(from decoder: Decoder) throws {
346369
let container = try decoder.container(keyedBy: CodingKeys.self)
347370
self.bypassDocumentValidation = try container.decodeIfPresent(Bool.self, forKey: .bypassDocumentValidation)
371+
self.comment = try container.decodeIfPresent(BSON.self, forKey: .comment)
348372
self.ordered = try container.decodeIfPresent(Bool.self, forKey: .ordered) ?? true
349373
self.writeConcern = try container.decodeIfPresent(WriteConcern.self, forKey: .writeConcern)
350374
}

Sources/MongoSwift/MongoCollection+FindAndModify.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ public struct FindOneAndDeleteOptions: FindAndModifyOptionsConvertible, Decodabl
187187
/// Specifies a collation to use.
188188
public var collation: BSONDocument?
189189

190+
/// A comment to help trace the operation through the database profiler,
191+
/// currentOp and logs. Can be any valid BSON type for server versions
192+
/// 4.4 and above but older server versions only support string comments
193+
/// (non-string types cause server-side errors). The default is to not send a value.
194+
public var comment: BSON?
195+
190196
/// A document or string that specifies the index to use to support the query. Only supported in server 4.4+.
191197
public var hint: IndexHint?
192198

@@ -209,6 +215,7 @@ public struct FindOneAndDeleteOptions: FindAndModifyOptionsConvertible, Decodabl
209215
internal func toFindAndModifyOptions() throws -> FindAndModifyOptions {
210216
try FindAndModifyOptions(
211217
collation: self.collation,
218+
comment: self.comment,
212219
hint: self.hint,
213220
letValue: self.let,
214221
maxTimeMS: self.maxTimeMS,
@@ -222,6 +229,7 @@ public struct FindOneAndDeleteOptions: FindAndModifyOptionsConvertible, Decodabl
222229
/// Convenience initializer allowing any/all parameters to be omitted/optional
223230
public init(
224231
collation: BSONDocument? = nil,
232+
comment: BSON? = nil,
225233
hint: IndexHint? = nil,
226234
`let`: BSONDocument? = nil,
227235
maxTimeMS: Int? = nil,
@@ -230,6 +238,7 @@ public struct FindOneAndDeleteOptions: FindAndModifyOptionsConvertible, Decodabl
230238
writeConcern: WriteConcern? = nil
231239
) {
232240
self.collation = collation
241+
self.comment = comment
233242
self.hint = hint
234243
self.let = `let`
235244
self.maxTimeMS = maxTimeMS
@@ -247,6 +256,12 @@ public struct FindOneAndReplaceOptions: FindAndModifyOptionsConvertible, Decodab
247256
/// Specifies a collation to use.
248257
public var collation: BSONDocument?
249258

259+
/// A comment to help trace the operation through the database profiler,
260+
/// currentOp and logs. Can be any valid BSON type for server versions
261+
/// 4.4 and above but older server versions only support string comments
262+
/// (non-string types cause server-side errors). The default is to not send a value.
263+
public var comment: BSON?
264+
250265
/// A document or string that specifies the index to use to support the query. Only supported in server 4.4+.
251266
public var hint: IndexHint?
252267

@@ -276,6 +291,7 @@ public struct FindOneAndReplaceOptions: FindAndModifyOptionsConvertible, Decodab
276291
try FindAndModifyOptions(
277292
bypassDocumentValidation: self.bypassDocumentValidation,
278293
collation: self.collation,
294+
comment: self.comment,
279295
hint: self.hint,
280296
letValue: self.let,
281297
maxTimeMS: self.maxTimeMS,
@@ -291,6 +307,7 @@ public struct FindOneAndReplaceOptions: FindAndModifyOptionsConvertible, Decodab
291307
public init(
292308
bypassDocumentValidation: Bool? = nil,
293309
collation: BSONDocument? = nil,
310+
comment: BSON? = nil,
294311
hint: IndexHint? = nil,
295312
`let`: BSONDocument? = nil,
296313
maxTimeMS: Int? = nil,
@@ -302,6 +319,7 @@ public struct FindOneAndReplaceOptions: FindAndModifyOptionsConvertible, Decodab
302319
) {
303320
self.bypassDocumentValidation = bypassDocumentValidation
304321
self.collation = collation
322+
self.comment = comment
305323
self.hint = hint
306324
self.let = `let`
307325
self.maxTimeMS = maxTimeMS
@@ -324,6 +342,12 @@ public struct FindOneAndUpdateOptions: FindAndModifyOptionsConvertible, Decodabl
324342
/// Specifies a collation to use.
325343
public var collation: BSONDocument?
326344

345+
/// A comment to help trace the operation through the database profiler,
346+
/// currentOp and logs. Can be any valid BSON type for server versions
347+
/// 4.4 and above but older server versions only support string comments
348+
/// (non-string types cause server-side errors). The default is to not send a value.
349+
public var comment: BSON?
350+
327351
/// A document or string that specifies the index to use to support the query. Only supported in server 4.4+.
328352
public var hint: IndexHint?
329353

@@ -354,6 +378,7 @@ public struct FindOneAndUpdateOptions: FindAndModifyOptionsConvertible, Decodabl
354378
arrayFilters: self.arrayFilters,
355379
bypassDocumentValidation: self.bypassDocumentValidation,
356380
collation: self.collation,
381+
comment: self.comment,
357382
hint: self.hint,
358383
letValue: self.let,
359384
maxTimeMS: self.maxTimeMS,
@@ -370,6 +395,7 @@ public struct FindOneAndUpdateOptions: FindAndModifyOptionsConvertible, Decodabl
370395
arrayFilters: [BSONDocument]? = nil,
371396
bypassDocumentValidation: Bool? = nil,
372397
collation: BSONDocument? = nil,
398+
comment: BSON? = nil,
373399
hint: IndexHint? = nil,
374400
`let`: BSONDocument? = nil,
375401
maxTimeMS: Int? = nil,
@@ -382,6 +408,7 @@ public struct FindOneAndUpdateOptions: FindAndModifyOptionsConvertible, Decodabl
382408
self.arrayFilters = arrayFilters
383409
self.bypassDocumentValidation = bypassDocumentValidation
384410
self.collation = collation
411+
self.comment = comment
385412
self.hint = hint
386413
self.let = `let`
387414
self.maxTimeMS = maxTimeMS

Sources/MongoSwift/MongoCollection+Indexes.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ extension MongoCollection {
415415
* Retrieves a list of the indexes currently on this collection.
416416
*
417417
* - Parameters:
418+
* - options: Optional `ListIndexesOptions` to use for the command
418419
* - session: Optional `ClientSession` to use when executing this command
419420
*
420421
* - Warning:
@@ -428,8 +429,11 @@ extension MongoCollection {
428429
* - `MongoError.LogicError` if the provided session is inactive.
429430
* - `MongoError.LogicError` if this collection's parent client has already been closed.
430431
*/
431-
public func listIndexes(session: ClientSession? = nil) -> EventLoopFuture<MongoCursor<IndexModel>> {
432-
let operation = ListIndexesOperation(collection: self, nameOnly: false)
432+
public func listIndexes(
433+
options: ListIndexesOptions? = nil,
434+
session: ClientSession? = nil
435+
) -> EventLoopFuture<MongoCursor<IndexModel>> {
436+
let operation = ListIndexesOperation(collection: self, nameOnly: false, options: options)
433437
return self._client.operationExecutor.execute(
434438
operation,
435439
client: self._client,
@@ -448,6 +452,7 @@ extension MongoCollection {
448452
* Retrieves a list of names of the indexes currently on this collection.
449453
*
450454
* - Parameters:
455+
* - options: Optional `ListIndexesOptions` to use for the command
451456
* - session: Optional `ClientSession` to use when executing this command
452457
*
453458
* - Returns:
@@ -457,8 +462,11 @@ extension MongoCollection {
457462
* - `MongoError.LogicError` if the provided session is inactive.
458463
* - `MongoError.LogicError` if this collection's parent client has already been closed.
459464
*/
460-
public func listIndexNames(session: ClientSession? = nil) -> EventLoopFuture<[String]> {
461-
let operation = ListIndexesOperation(collection: self, nameOnly: true)
465+
public func listIndexNames(
466+
options: ListIndexesOptions? = nil,
467+
session: ClientSession? = nil
468+
) -> EventLoopFuture<[String]> {
469+
let operation = ListIndexesOperation(collection: self, nameOnly: true, options: options)
462470
return self._client.operationExecutor.execute(
463471
operation,
464472
client: self._client,

0 commit comments

Comments
 (0)