This package requires Swift 6.0 or greater.
| Platform | Status |
|---|---|
| 💬 Documentation | |
| 🐧 Linux | |
| 🍏 Darwin |
TODO: add more snippets
import NIOCore
import NIOPosix
import MongoDB
let executors: MultiThreadedEventLoopGroup = .init(numberOfThreads: 2)
let bootstrap: Mongo.DriverBootstrap = MongoDB / ["mongo-0", "mongo-1"] /? {
$0.executors = MultiThreadedEventLoopGroup.singleton
$0.appname = "example app"
}
let configuration: Mongo.ReplicaSetConfiguration = try await bootstrap.withSessionPool {
try await $0.run(
command: Mongo.ReplicaSetGetConfiguration.init(),
against: .admin
)
}
print(configuration)
// ...Development environments for MongoDB drivers can be challenging to set up. The easiest way to work on swift-mongodb is to use Docker. This repository contains some configurations to help you get started.
# launch a cluster of Docker containers, each hosting a `mongod` instance
docker compose -f .github/mongonet/docker-compose.yml up -d
docker exec -t mongonet-mongo-0-1 /bin/mongosh --file /create-replica-set.jsImportantly, your own devcontainer must be connected to the cluster’s Docker network (mongonet).
services:
your-vscode-container:
image: your-devcontainer-image
hostname: vscode
networks:
- mongonet
networks:
mongonet:
external: trueThis library is Apache 2.0 licensed. It originally began as a re-write of MongoKitten by Joannis Orlandos and Robbert Brandsma.
All products depended-upon by this package are Foundation-free when compiled for a Linux target. Note that some package dependencies do vend products that import Foundation, but Swift links binaries at the product level, and this library does not depend on any such products.
Rarest packages:
-
Rationale: this package provides the
TraceableErrorsmodule which the driver uses to provide rich diagnostics. The driver does not depend on any parser targets. -
Rationale: this package implements cryptographic algorithms the driver uses to complete authentication with
mongod/mongosservers.
Other packages:
-
Rationale: this package provides data structures that improve the runtime complexity of several algorithms the driver uses internally. Moreover, the driver’s
swift-niodependency already depends on one of this package’s modules (DequeModule) anyway. -
Rationale: networking.
-
Rationale: networking.
Note: This library depends on the
NIOSSLproduct fromswift-nio-ssl, which imports Foundation on Apple platforms only.NIOSSLis Foundation-free on all other platforms.