1.1.0
The MongoDB Swift driver team is pleased to announce our 1.1.0 release.
Highlights
New BSON Library
Last week, we released version 3.0.0 of SwiftBSON. This is a brand new, pure Swift BSON library. While the internals are all-new, the API is identical to the one that previously lived in the driver with a few additions as described in the release notes, and we've now switched the driver to depend on this library.
For convenience, we re-export all symbols from SwiftBSON from MongoSwift and MongoSwiftSync, so you can continue to use BSON types as if they were defined directly in the driver with no breaking changes.
Event Loop "Binding" for Core Async Driver Types
Previously, there was no way to specify at the API level a particular EventLoop that a core driver type (client, database, or collection) should return EventLoopFutures on. We've now introduced a special EventLoopBoundClient type to support this for clients, and added support directly to MongoDatabase and MongoCollection for it as well. Please see our Multithreaded Usage Guide for more details.
Aggregation Improvements
We've added a new helper method to MongoDatabase via SWIFT-577 to support performing database-level aggregations.
We've also added support via SWIFT-506 to both MongoDatabase.aggregate and MongoCollection.aggregate for specifying a Codable type that the returned MongoCursor should decode resulting documents into. Previously, these methods could only return MongoCursor<BSONDocument>s. For example:
/// Collection type.
struct Person: Codable {
let _id: BSONObjectID
let name: String
let age: Int
let favoriteColor: String
}
let coll = db.collection("people", withType: Person.self)
try coll.insertMany([
Person(_id: BSONObjectID(), name: "Kaitlin", age: 26, favoriteColor: "blue")
Person(_id: BSONObjectID(), name: "Buffalo", age: 27, favoriteColor: "green")
]).wait()
/// Transformed aggregation output type.
struct PersonOutput: Codable {
let name: String
let age: Int
}
let resultsFuture = coll.aggregate([
["$project": ["age": 1, "name": 1, "_id": 0]] // only keep the age and name fields
], withOutputType: PersonOutput.self).flatMap { cursor in
cursor.toArray()
}
// prints [PersonOutput(name: "Kaitlin", age: 26), PersonOutput(name: "Buffalo", age: 27)]
print(try resultsFuture.wait())MongoClientOptions Improvements
Previously, a number of driver options were only specifiable via connection string, and not supported via MongoClientOptions. We've now added support for specifying a number of options via the options struct as well, such as replicaSet and serverSelectionTimeoutMS.
Included Tickets
Bug
- [SWIFT-957] - DecodingError when encountering dropDatabase event in change stream
- [SWIFT-958] - Ensure nil is returned from cursor before returning LogicError
- [SWIFT-969] - Manually clean up mongoc_uri_t when ConnectionString options validation fails
- [SWIFT-974] - Cursor gets leaked in findOne after DecodingError
- [SWIFT-1045] - MongoClient initializer performs blocking DNS lookup
New Feature
- [SWIFT-481] - Support index all paths
- [SWIFT-828] - Hidden Indexes
- [SWIFT-577] - Add database aggregation helper
- [SWIFT-1028] - Create EventLoopBoundMongoClient type
- [SWIFT-1029] - Implement EventLoop binding support for database and collection objects
- [SWIFT-1030] - Implement EventLoop binding support for change streams and cursors
- [SWIFT-1031] - Implement EventLoop binding support for sessions
- [SWIFT-459] - Add a renameCollection helper
- [SWIFT-519] - Support startAfter option for change streams
- [SWIFT-506] - Allow users to specify the output type of an aggregation
Task
- [SWIFT-734] - Maintain multiple versions of the documentation
- [SWIFT-791] - Support shorter SCRAM conversation
- [SWIFT-854] - Organize API documentation in a more useful way
- [SWIFT-936] - Update the driver to use the new BSON library
- [SWIFT-1010] - Test against Swift 5.3 + Linux on Evergreen
- [SWIFT-1034] - Update readme with how to sort all records after running collection.find()
- [SWIFT-1092] - Vendor libmongoc 1.17.4
- [SWIFT-763] - Deprecate geoHaystack and geoSearch
Improvement
- [SWIFT-805] - Make ExceededTimeLimit retryable writes error
- [SWIFT-872] - Reduce default keepalive time to align with Azure defaults
- [SWIFT-903] - Add compressors option to MongoClientOptions
- [SWIFT-905] - Add heartbeatFrequencyMS option to MongoClientOptions
- [SWIFT-906] - Add localThresholdMS option to MongoClientOptions
- [SWIFT-907] - Add serverSelectionTimeoutMS option to MongoClientOptions
- [SWIFT-909] - Add zLibCompressionLevel option to MongoClientOptions
- [SWIFT-897] - Add appname option to MongoClientOptions
- [SWIFT-898] - Add replicaSet option to MongoClientOptions
- [SWIFT-901] - Add tlsInsecure option to MongoClientOptions
- [SWIFT-912] - Error if minPoolSize option is provided in connection string
- [SWIFT-929] - Validate options provided via MongoClientOptions
- [SWIFT-1015] - Only create monitoring events if the user is actually subscribing to them
- [SWIFT-1072] - Improve performance of insertion