-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathDropCollectionOperation.swift
30 lines (26 loc) · 1.14 KB
/
DropCollectionOperation.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
import CLibMongoC
/// An operation corresponding to a "drop" command on a collection.
internal struct DropCollectionOperation<T: Codable>: Operation {
private let collection: MongoCollection<T>
private let options: DropCollectionOptions?
internal init(collection: MongoCollection<T>, options: DropCollectionOptions?) {
self.collection = collection
self.options = options
}
internal func execute(using connection: Connection, session: ClientSession?) throws {
let command: BSONDocument = ["drop": .string(self.collection.name)]
let opts = try encodeOptions(options: options, session: session)
do {
try self.collection.withMongocCollection(from: connection) { collPtr in
try runMongocCommand(command: command, options: opts) { cmdPtr, optsPtr, replyPtr, error in
mongoc_collection_write_command_with_opts(collPtr, cmdPtr, optsPtr, replyPtr, &error)
}
}
} catch let error as MongoErrorProtocol {
guard !error.isNsNotFound else {
return
}
throw error
}
}
}