You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -6,6 +6,90 @@ A fast, pure swift [MongoDB](https://mongodb.com) driver based on [Swift NIO](ht
6
6
7
7
MongoKitten is a fully asynchronous driver, which means that it doesn't block any threads. This also means that it can be used in any asynchronous environment, such as [Vapor](https://github.com/vapor/vapor) or [Hummingbird](https://github.com/hummingbird-project/hummingbird).
8
8
9
+
## Table of Contents
10
+
11
+
-[Docs \& Community](#docs--community)
12
+
-[Projects](#projects)
13
+
-[Installation](#installation)
14
+
-[Set up MongoDB server](#set-up-mongodb-server)
15
+
-[Add MongoKitten to your Swift project 🚀](#add-mongokitten-to-your-swift-project-)
16
+
-[Add Meow (Optional)](#add-meow-optional)
17
+
-[Basic usage](#basic-usage)
18
+
-[Connect vs. LazyConnect](#connect-vs-lazyconnect)
19
+
-[CRUD](#crud)
20
+
-[Create](#create)
21
+
-[Read](#read)
22
+
-[Cursors](#cursors)
23
+
-[Fetching results](#fetching-results)
24
+
-[Cursors are generic](#cursors-are-generic)
25
+
-[Update \& Delete](#update--delete)
26
+
-[Indexes](#indexes)
27
+
-[Aggregation](#aggregation)
28
+
-[Transactions](#transactions)
29
+
-[GridFS](#gridfs)
30
+
-[About BSON](#about-bson)
31
+
-[Literals](#literals)
32
+
-[Just Another Collection](#just-another-collection)
33
+
-[Think twice before converting between `Document` and `Dictionary`](#think-twice-before-converting-between-document-and-dictionary)
34
+
-[Codable](#codable)
35
+
-[Advanced Features](#advanced-features)
36
+
-[Change Streams](#change-streams)
37
+
-[Logging and Monitoring](#logging-and-monitoring)
@@ -54,16 +138,7 @@ Meow is an ORM that resides in this same package.
54
138
.product(name: "Meow", package: "MongoKitten"),
55
139
```
56
140
57
-
# FAQ
58
-
59
-
<details>
60
-
<summary>I can't connect to MongoDB, authentication fails!</summary>
61
-
62
-
1. Make sure you've specified `authSource=admin`, unless you know what your authSource is. MongoDB's default value is really confusing.
63
-
2. If you've specified an `authMechanism`, try removing it. MongoKitten can detect the correct one automatically.
64
-
</details>
65
-
66
-
# 🚲 Basic usage
141
+
# Basic usage
67
142
68
143
First, connect to a database:
69
144
@@ -148,7 +223,7 @@ Connect's advantage is that a booted server is known to have a connection. Any i
148
223
149
224
LazyConnect is helpful during development, because connecting to MongoDB can be a time-consuming process in certain setups. LazyConnect allows you to start working with your system almost immediately, without waiting for MongoKitten. Another advantage is that cluster outages or offly timed topology changes do not influence app boot. Therefore, MongoKitten can simply attempt to recover in the background. However, should something go wrong it can be hard to debug this.
150
225
151
-
## CRUD (Create, Read, Update, Delete)
226
+
## CRUD
152
227
153
228
Before doing operations, you need access to a collection where you store your models. This is MongoDB's equivalent to a table.
154
229
@@ -157,7 +232,7 @@ Before doing operations, you need access to a collection where you store your mo
@@ -309,9 +384,18 @@ for try await user in pipeline {
309
384
310
385
## Transactions
311
386
312
-
```swift
313
-
tryawait db.transaction { transaction in
314
-
// Do something with the transaction
387
+
388
+
Execute multiple operations atomically:
389
+
390
+
```swift
391
+
tryawait db.transaction { session in
392
+
let users = db["users"]
393
+
let accounts = db["accounts"]
394
+
395
+
tryawait users.insert(newUser)
396
+
tryawait accounts.insert(newAccount)
397
+
398
+
// Changes are only committed if no errors occur
315
399
}
316
400
```
317
401
@@ -383,7 +467,7 @@ for try await chunk in file {
383
467
}
384
468
```
385
469
386
-
# 📦 About BSON & Documents
470
+
# About BSON
387
471
388
472
MongoDB is a document database that uses BSON under the hood to store JSON-like data. MongoKitten implements the [BSON specification](http://bsonspec.org) in its companion project, [OpenKitten/BSON](https://github.com/OpenKitten/BSON). You can find out more about our BSON implementation in the separate BSON repository, but here are the basics:
389
473
@@ -428,7 +512,7 @@ let username = documentA["username"] as? String
428
512
429
513
Our `Document` type is implemented in an optimized, efficient way and provides many useful features to read and manipulate data, including features not present on the Swift `Dictionary` type. On top of that, `Document` also implements most APIs present on `Dictionary`, so there is very little learning curve.
430
514
431
-
#💾 Codable
515
+
##Codable
432
516
433
517
MongoKitten supports the `Encodable` and `Decodable` (`Codable`) protocols by providing the `BSONEncoder` and `BSONDecoder` types. Working with our encoders and decoders is very similar to working with the Foundation `JSONEncoder` and `JSONDecoder` classes, with the difference being that `BSONEncoder` produces instances of `Document` and `BSONDecoder` accepts instances of `Document`, instead of `Data`.
434
518
@@ -468,7 +552,103 @@ A few notes:
468
552
- Nested structs and classes are most often encoded as embedded documents
469
553
- You can customize the representations using encoding/decoding strategies
470
554
471
-
# Meow
555
+
# Advanced Features
556
+
557
+
## Change Streams
558
+
559
+
MongoKitten provides powerful support for MongoDB Change Streams, allowing you to monitor real-time changes to your collections:
0 commit comments