Skip to content

Commit b6bc5b7

Browse files
authored
SWIFT-621 Provide default values for WriteModel options associated values (#439)
1 parent cf2894d commit b6bc5b7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

Sources/MongoSwift/MongoCollection+BulkWrite.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public enum WriteModel<CollectionType: Codable> {
4343
/// Parameters:
4444
/// - A `Document` representing the match criteria.
4545
/// - `options`: Optional `DeleteModelOptions`.
46-
case deleteOne(Document, options: DeleteModelOptions?)
46+
case deleteOne(Document, options: DeleteModelOptions? = nil)
4747
/// A `deleteMany`.
4848
/// Parameters:
4949
/// - A `Document` representing the match criteria.
5050
/// - `options`: Optional `DeleteModelOptions`.
51-
case deleteMany(Document, options: DeleteModelOptions?)
51+
case deleteMany(Document, options: DeleteModelOptions? = nil)
5252
/// An `insertOne`.
5353
/// Parameters:
5454
/// - A `T` to insert.
@@ -58,19 +58,19 @@ public enum WriteModel<CollectionType: Codable> {
5858
/// - `filter`: A `Document` representing the match criteria.
5959
/// - `replacement`: A `T` to use as the replacement value.
6060
/// - `options`: Optional `ReplaceOneModelOptions`.
61-
case replaceOne(filter: Document, replacement: CollectionType, options: ReplaceOneModelOptions?)
61+
case replaceOne(filter: Document, replacement: CollectionType, options: ReplaceOneModelOptions? = nil)
6262
/// An `updateOne`.
6363
/// Parameters:
6464
/// - `filter`: A `Document` representing the match criteria.
6565
/// - `update`: A `Document` containing update operators.
6666
/// - `options`: Optional `UpdateModelOptions`.
67-
case updateOne(filter: Document, update: Document, options: UpdateModelOptions?)
67+
case updateOne(filter: Document, update: Document, options: UpdateModelOptions? = nil)
6868
/// An `updateMany`.
6969
/// Parameters:
7070
/// - `filter`: A `Document` representing the match criteria.
7171
/// - `update`: A `Document` containing update operators.
7272
/// - `options`: Optional `UpdateModelOptions`.
73-
case updateMany(filter: Document, update: Document, options: UpdateModelOptions?)
73+
case updateMany(filter: Document, update: Document, options: UpdateModelOptions? = nil)
7474

7575
/// Adds this model to the provided `mongoc_bulk_t`, using the provided encoder for encoding options and
7676
/// `CollectionType` values if needed. If this is an `insertOne`, returns the `_id` field of the inserted

Tests/MongoSwiftSyncTests/MongoCollection+BulkWriteTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ final class MongoCollection_BulkWriteTests: MongoSwiftTestCase {
123123
try self.createFixtures(4)
124124

125125
let requests: [WriteModel<Document>] = [
126-
.updateOne(filter: ["_id": 2], update: ["$inc": ["x": 1]], options: nil),
127-
.updateMany(filter: ["_id": ["$gt": 2]], update: ["$inc": ["x": -1]], options: nil),
126+
.updateOne(filter: ["_id": 2], update: ["$inc": ["x": 1]]),
127+
.updateMany(filter: ["_id": ["$gt": 2]], update: ["$inc": ["x": -1]]),
128128
.updateOne(
129129
filter: ["_id": 5],
130130
update: ["$set": ["x": 55]],
@@ -135,7 +135,7 @@ final class MongoCollection_BulkWriteTests: MongoSwiftTestCase {
135135
update: ["$set": ["x": 66]],
136136
options: UpdateModelOptions(upsert: true)
137137
),
138-
.updateMany(filter: ["x": ["$gt": 50]], update: ["$inc": ["x": 1]], options: nil)
138+
.updateMany(filter: ["x": ["$gt": 50]], update: ["$inc": ["x": 1]])
139139
]
140140

141141
let result: BulkWriteResult! = try self.coll.bulkWrite(requests)
@@ -160,8 +160,8 @@ final class MongoCollection_BulkWriteTests: MongoSwiftTestCase {
160160
try self.createFixtures(4)
161161

162162
let requests: [WriteModel<Document>] = [
163-
.deleteOne(["_id": 1], options: nil),
164-
.deleteMany(["_id": ["$gt": 2]], options: nil)
163+
.deleteOne(["_id": 1]),
164+
.deleteMany(["_id": ["$gt": 2]])
165165
]
166166

167167
let result: BulkWriteResult! = try self.coll.bulkWrite(requests)
@@ -182,9 +182,9 @@ final class MongoCollection_BulkWriteTests: MongoSwiftTestCase {
182182
update: ["$inc": ["x": 1]],
183183
options: nil
184184
),
185-
.updateMany(filter: ["_id": ["$gt": 1]], update: ["$inc": ["x": 1]], options: nil),
185+
.updateMany(filter: ["_id": ["$gt": 1]], update: ["$inc": ["x": 1]]),
186186
.insertOne(["_id": 4]),
187-
.deleteMany(["x": ["$nin": [24, 34]]], options: nil),
187+
.deleteMany(["x": ["$nin": [24, 34]]]),
188188
.replaceOne(
189189
filter: ["_id": 4],
190190
replacement: ["_id": 4, "x": 44],

0 commit comments

Comments
 (0)