Skip to content

Commit ff0c870

Browse files
committed
chore: updated the README.md
1 parent 6854323 commit ff0c870

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

README.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
- aggregation pipeline
1818
- replica sets
1919
- support for SCRAM-SHA-256 (MongoDB 4.x)
20-
- support for GridFS ([See](https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.rst))
21-
- support for change streams api ([See](https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst))
22-
- support for bulk writes ([See](https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#write))
23-
- support for driver sessions ([See](https://github.com/mongodb/specifications/blob/master/source/sessions/driver-sessions.rst))
24-
- support for driver transactions ([See](https://github.com/mongodb/specifications/blob/master/source/transactions/transactions.rst))
25-
- support for command monitoring ([See](https://github.com/mongodb/specifications/blob/master/source/command-monitoring/command-monitoring.rst))
26-
- support for retryable reads ([See](https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.rst))
27-
- support for retryable writes ([See](https://github.com/mongodb/specifications/blob/master/source/retryable-writes/retryable-writes.rst))
20+
- support for GridFS ([See](https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.md))
21+
- support for change streams api ([See](https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.md))
22+
- support for bulk writes ([See](https://github.com/mongodb/specifications/blob/master/source/crud/crud.md#write))
23+
- support for driver sessions ([See](https://github.com/mongodb/specifications/blob/master/source/sessions/driver-sessions.md))
24+
- support for driver transactions ([See](https://github.com/mongodb/specifications/blob/master/source/transactions/transactions.md))
25+
- support for command monitoring ([See](https://github.com/mongodb/specifications/blob/master/source/command-logging-and-monitoring/command-logging-and-monitoring.md))
26+
- support for retryable reads ([See](https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.md))
27+
- support for retryable writes ([See](https://github.com/mongodb/specifications/blob/master/source/retryable-writes/retryable-writes.md))
2828
- support for simple structs using the Mongo.Encoder protocol
2929
- support for complex and nested documents using the `Mongo.Collection` macros
30-
- support for streaming protocol ([See](https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-monitoring.rst#streaming-protocol))
30+
- support for streaming protocol ([See](https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-monitoring.md#streaming-protocol))
3131
- support for migration scripts
3232
- support for compression for zlib and zstd ([See](https://github.com/mongodb/specifications/blob/07b7649cc5c805ef4f85fccddf39226add7114e6/source/compression/OP_COMPRESSED.md))
3333

@@ -50,7 +50,7 @@ Add `mongodb_driver` to your mix.exs `deps`.
5050

5151
```elixir
5252
defp deps do
53-
[{:mongodb_driver, "~> 1.4.0"}]
53+
[{:mongodb_driver, "~> 1.5.0"}]
5454
end
5555
```
5656

@@ -128,6 +128,29 @@ Using `$in`
128128
Mongo.find(:mongo, "users", %{email: %{"$in" => ["[email protected]", "[email protected]"]}})
129129
```
130130

131+
## How to use the `Mongo.Stream`?
132+
133+
Most query functions return a `Mongo.Stream` struct that implements the `Enumerable` protocol. The module checks out
134+
the session and streams the batches from the server until the last batch has been received.
135+
The session is then checked in for reuse. [Sessions](https://github.com/mongodb/specifications/blob/master/source/sessions/driver-sessions.md) are
136+
temporary and reusable data structures, e.g. to support transactions. They are required by the Mongo DB driver specification.
137+
138+
The use of internal structures of the `Mongo.Stream` struct is therefore not planned. For example, the following code results in an open session and the `docs` will only contain the first batch:
139+
140+
```elixir
141+
%Mongo.Stream{docs: docs} = Mongo.aggregate(@topology, collection, pipeline, opts)
142+
Enum.map(docs, fn elem -> elem end)
143+
```
144+
145+
The `Mongo.Stream` struct should therefore always be processed by an `Enum` or `Stream` function so that the session management
146+
can take place automatically:
147+
148+
```elixir
149+
@topology
150+
|> Mongo.aggregate(collection, pipeline, opts)
151+
|> Enum.map(fn elem -> elem end)
152+
```
153+
131154
### Inserts
132155

133156
To insert a single document:
@@ -1228,6 +1251,9 @@ $ mongod --sslMode allowSSL --sslPEMKeyFile /path/to/mongodb.pem
12281251
- For `--sslMode` you can use one of `allowSSL` or `preferSSL`
12291252
- You can enable any other options you want when starting `mongod`
12301253

1254+
## Additional articles
1255+
* [Connecting to MongoDB with Elixir](https://zookzook.github.io/2024/08-25.html)
1256+
12311257
## Copyright and License
12321258

12331259
Copyright 2015 Eric Meadows-Jönsson and Justin Wood \

0 commit comments

Comments
 (0)