-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathMongoCollection+FindAndModify.swift
89 lines (86 loc) · 4.02 KB
/
MongoCollection+FindAndModify.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import MongoSwift
/// An extension of `MongoCollection` encapsulating find and modify operations.
extension MongoCollection {
/**
* Finds a single document and deletes it, returning the original.
*
* - Parameters:
* - filter: `Document` representing the match criteria
* - options: Optional `FindOneAndDeleteOptions` to use when executing the command
* - session: Optional `ClientSession` to use when executing this command
*
* - Returns: The deleted document, represented as a `CollectionType`, or `nil` if no document was deleted.
*
* - Throws:
* - `UserError.invalidArgumentError` if any of the provided options are invalid.
* - `UserError.logicError` if the provided session is inactive.
* - `ServerError.commandError` if an error occurs that prevents the command from executing.
* - `ServerError.writeError` if an error occurs while executing the command.
* - `DecodingError` if the deleted document cannot be decoded to a `CollectionType` value.
*/
@discardableResult
public func findOneAndDelete(
_ filter: Document,
options: FindOneAndDeleteOptions? = nil,
session: ClientSession? = nil
) throws -> CollectionType? {
fatalError("unimplemented")
}
/**
* Finds a single document and replaces it, returning either the original or the replaced document.
*
* - Parameters:
* - filter: `Document` representing the match criteria
* - replacement: a `CollectionType` to replace the found document
* - options: Optional `FindOneAndReplaceOptions` to use when executing the command
* - session: Optional `ClientSession` to use when executing this command
*
* - Returns: A `CollectionType`, representing either the original document or its replacement,
* depending on selected options, or `nil` if there was no match.
*
* - Throws:
* - `UserError.invalidArgumentError` if any of the provided options are invalid.
* - `UserError.logicError` if the provided session is inactive.
* - `ServerError.commandError` if an error occurs that prevents the command from executing.
* - `ServerError.writeError` if an error occurs while executing the command.
* - `DecodingError` if the replaced document cannot be decoded to a `CollectionType` value.
* - `EncodingError` if `replacement` cannot be encoded to a `Document`.
*/
@discardableResult
public func findOneAndReplace(
filter: Document,
replacement: CollectionType,
options: FindOneAndReplaceOptions? = nil,
session: ClientSession? = nil
) throws -> CollectionType? {
fatalError("unimplemented")
}
/**
* Finds a single document and updates it, returning either the original or the updated document.
*
* - Parameters:
* - filter: `Document` representing the match criteria
* - update: a `Document` containing updates to apply
* - options: Optional `FindOneAndUpdateOptions` to use when executing the command
* - session: Optional `ClientSession` to use when executing this command
*
* - Returns: A `CollectionType` representing either the original or updated document,
* depending on selected options, or `nil` if there was no match.
*
* - Throws:
* - `UserError.invalidArgumentError` if any of the provided options are invalid.
* - `UserError.logicError` if the provided session is inactive.
* - `ServerError.commandError` if an error occurs that prevents the command from executing.
* - `ServerError.writeError` if an error occurs while executing the command.
* - `DecodingError` if the updated document cannot be decoded to a `CollectionType` value.
*/
@discardableResult
public func findOneAndUpdate(
filter: Document,
update: Document,
options: FindOneAndUpdateOptions? = nil,
session: ClientSession? = nil
) throws -> CollectionType? {
fatalError("unimplemented")
}
}