Skip to content

Commit 86a20a8

Browse files
committed
chore: code examples adjusted
1 parent ff0c870 commit 86a20a8

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,25 @@ Failing operations return a `{:error, error}` tuple where `error` is a
113113
Using `$and`
114114

115115
```elixir
116-
Mongo.find(:mongo, "users", %{"$and" => [%{email: "[email protected]"}, %{first_name: "first_name"}]})
116+
@topology
117+
|> Mongo.find("users", %{"$and" => [%{email: "[email protected]"}, %{first_name: "first_name"}]})
118+
|> Enum.to_list()
117119
```
118120

119121
Using `$or`
120122

121123
```elixir
122-
Mongo.find(:mongo, "users", %{"$or" => [%{email: "[email protected]"}, %{first_name: "first_name"}]})
124+
@topology
125+
|> Mongo.find("users", %{"$or" => [%{email: "[email protected]"}, %{first_name: "first_name"}]})
126+
|> Enum.to_list()
123127
```
124128

125129
Using `$in`
126130

127131
```elixir
128-
Mongo.find(:mongo, "users", %{email: %{"$in" => ["[email protected]", "[email protected]"]}})
132+
@topology
133+
|> Mongo.find("users", %{email: %{"$in" => ["[email protected]", "[email protected]"]}})
134+
|> Enum.to_list()
129135
```
130136

131137
## How to use the `Mongo.Stream`?
@@ -148,7 +154,7 @@ can take place automatically:
148154
```elixir
149155
@topology
150156
|> Mongo.aggregate(collection, pipeline, opts)
151-
|> Enum.map(fn elem -> elem end)
157+
|> Enum.to_list()
152158
```
153159

154160
### Inserts
@@ -218,7 +224,9 @@ In those cases, driver users should represent documents using a list of tuples (
218224
order. Example:
219225

220226
```elixir
221-
Mongo.find(top, "users", %{}, sort: [last_name: 1, first_name: 1, _id: 1])
227+
@topology
228+
|> Mongo.find("users", %{}, sort: [last_name: 1, first_name: 1, _id: 1])
229+
|> Enum.to_list()
222230
```
223231

224232
The query above will sort users by last name, then by first name and finally by ID. If an Elixir map had been used to
@@ -962,14 +970,14 @@ You can use the `:timeout` as a global option to override the default value:
962970

963971
```elixir
964972
# Starts an pooled connection
965-
{:ok, conn} = Mongo.start_link(url: "mongodb://localhost:27017/db-name", timeout: 60_000)
973+
{:ok, top} = Mongo.start_link(url: "mongodb://localhost:27017/db-name", timeout: 60_000)
966974
```
967975

968976
Each single connection uses `60_000` (60 seconds) as the timeout value instead of `15_000`. But you can override the default value by
969977
using the `:timeout` option, when running a single command:
970978

971-
```elixr
972-
Mongo.find(conn, "dogs", %{}, timeout: 120_000)
979+
```elixir
980+
Mongo.find(top, "dogs", %{}, timeout: 120_000)
973981
```
974982

975983
Now the driver will use 120 seconds as the timeout for the single query.
@@ -1034,7 +1042,7 @@ To create indexes you can call the function `Mongo.create_indexes/4`:
10341042

10351043
```elixir
10361044
indexes = [[key: [files_id: 1, n: 1], name: "files_n_index", unique: true]]
1037-
Mongo.create_indexes(topology_pid, "my_collection", indexes, opts)
1045+
Mongo.create_indexes(top, "my_collection", indexes, opts)
10381046
```
10391047

10401048
You specify the `indexes` parameter as a keyword list with all options described in the documentation of the [createIndex](https://docs.mongodb.com/manual/reference/command/createIndexes/#dbcmd.createIndexes) command.
@@ -1080,7 +1088,7 @@ bulk = "bulk"
10801088
|> OrderedBulk.delete_one(%{kind: "cat"})
10811089
|> OrderedBulk.delete_one(%{kind: "cat"})
10821090

1083-
result = Mongo.BulkWrite.write(:mongo, bulk, w: 1)
1091+
result = Mongo.BulkWrite.write(@topology, bulk, w: 1)
10841092
```
10851093

10861094
In the following example we import 1.000.000 integers into the MongoDB using the stream api:
@@ -1214,8 +1222,8 @@ iex> Mongo.EventHandler.start()
12141222
iex> {:ok, conn} = Mongo.start_link(url: "mongodb://localhost:27017/test")
12151223
{:ok, #PID<0.226.0>}
12161224
iex> Mongo.find_one(conn, "test", %{})
1217-
[info] Received command: %Mongo.Events.CommandStartedEvent{command: [find: "test", ...
1218-
[info] Received command: %Mongo.Events.CommandSucceededEvent{command_name: :find, ...
1225+
[info] Received command: %Mongo.Events.CommandStartedEvent{command: [find: "test", ...
1226+
[info] Received command: %Mongo.Events.CommandSucceededEvent{command_name: :find, ...
12191227
```
12201228

12211229
## Testing

0 commit comments

Comments
 (0)