Swiftpack.co - Package - OpenKitten/MongoKitten

Please leave a star to show your support for the project.

Swift 3.1.0 License Build Status



MongoKitten is a native, production-ready MongoDB driver written in pure Swift. It is the fastest MongoDB driver available on any platform, while providing a great Swift API that is a joy to use.

Core features

  • Production ready
  • No complex setup procedure, just import and go
  • Extremely performant 🚀
  • Pure Swift
  • Great API
  • Fast with support for new MongoDB and Swift features and versions


  • A MongoDB server (local or online) running MongoDB 2.6 or above. (MongoDB 3.2 or 3.4 is recommmended)
  • Swift 3.1 or greater

Linux requries the libssl-dev library to be installed.

Setting up MongoDB

Install MongoDB for Ubuntu, macOS or any other supported Linux Distro.

Alternatively; make use of a DAAS (Database-as-a-service) like Atlas, MLab, IBM Cloud or any other of the many services.

Getting started

Add MongoKitten to your Package.swift:

Swift 3: .Package(url: "https://github.com/OpenKitten/MongoKitten.git", majorVersion: 4)

Swift 4: .package(url: "https://github.com/OpenKitten/MongoKitten.git", from: "4.0.0")

For Swift 4 you also need to add MongoKitten to your target's dependencies and optionally ExtendedJSON for people using that:

.target(name: "MyTarget", dependencies: ["MongoKitten"])

After a swift package update, you can now use MongoKitten:

import MongoKitten

let myDatabase = try MongoKitten.Database("mongodb://localhost/my_database")
let myCollection = myDatabase["my_collection"]

for document in try myCollection.find("foo" > 42) {
    // do something with document

For more information on how to use MongoKitten, visit the documentation.

Building for performance

Always compile MongoKitten in release mode for production and benchmarks. MongoKitten has proven to be 100-200x faster on release mode compared to debug compilation. Both Xcode and SPM use debug compilation by default.

swift build -c release


Many articles on medium are listed here and here.

We host the MongoKitten documentation including dash docset here.


Join our slack here and become a part of the welcoming community.

Learn more about contributing here.

Contributors are always welcome. Questions can be discussed on slack or in github issues. We also take part in the Contributor Covenant Code of Conduct.


We're accepting donations for our project here. We hope to set up a good test environment as well as many docs, tutorials and examples.


MongoKitten is faster than other MongoDB drivers.

Driver | Execution time -------|---------------- MongoKitten 4 | 525ms Java (post JIT optimizations) | 585ms C | 605ms Ruby | 1200ms Java (pre JIT optimizations) | 1205ms


MongoKitten is licensed under the MIT license.


Stars: 441
Help us keep the lights on


5.0.0-beta.1 - Oct 25, 2018

4.0.18 - Apr 2, 2018

Update for Swift 4.1

4.1.3 - Apr 1, 2018

Fix SNI leaks and Swift 4.1 compilation

4.0.17 - Mar 26, 2018

Fixed a memory leak - thanks @valeriomazzeo

5.0.0-alpha.1 - Nov 23, 2017

This update is being designed to work with Vapor 3's upcoming async layer. Since Vapor 3 async is currently in alpha, the underlying APIs are unstable and MongoKitten temporarily depends on the Vapor 3 monolithic package. In the future, MongoKitten will depend on Vapor 3's TLS, Async and TCP layers only. These layers have also been designed by me (the MongoKitten author) and will work nicely.

Advantages of async:

  • Performance
  • Better Concurrency

General MK5 features:

  • Slimmer, leaner API
  • Almost identical to MongoKitten 4 aside from the async update
  • More maintainable, stable and future-proof codebase
  • Manual connection management
  • Better (default) connection management

Coming soon:

  • MongoDb 3.6's new protocol support
  • Compression
  • TLS revamp (including X.509 authentication)
  • MongoDB 3.6 aggregate features

You should not use this version if you do not intend to take advantage of Async.