@@ -113,19 +113,25 @@ Failing operations return a `{:error, error}` tuple where `error` is a
113
113
Using ` $and `
114
114
115
115
``` 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 ()
117
119
```
118
120
119
121
Using ` $or `
120
122
121
123
``` 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 ()
123
127
```
124
128
125
129
Using ` $in `
126
130
127
131
``` 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 ()
129
135
```
130
136
131
137
## How to use the ` Mongo.Stream ` ?
@@ -148,7 +154,7 @@ can take place automatically:
148
154
``` elixir
149
155
@topology
150
156
|> Mongo .aggregate (collection, pipeline, opts)
151
- |> Enum .map ( fn elem -> elem end )
157
+ |> Enum .to_list ( )
152
158
```
153
159
154
160
### Inserts
@@ -218,7 +224,9 @@ In those cases, driver users should represent documents using a list of tuples (
218
224
order. Example:
219
225
220
226
``` 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 ()
222
230
```
223
231
224
232
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:
962
970
963
971
``` elixir
964
972
# 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 )
966
974
```
967
975
968
976
Each single connection uses ` 60_000 ` (60 seconds) as the timeout value instead of ` 15_000 ` . But you can override the default value by
969
977
using the ` :timeout ` option, when running a single command:
970
978
971
- ``` elixr
972
- Mongo.find(conn , "dogs", %{}, timeout: 120_000)
979
+ ``` elixir
980
+ Mongo .find (top , " dogs" , %{}, timeout: 120_000 )
973
981
```
974
982
975
983
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`:
1034
1042
1035
1043
``` elixir
1036
1044
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)
1038
1046
```
1039
1047
1040
1048
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"
1080
1088
|> OrderedBulk .delete_one (%{kind: " cat" })
1081
1089
|> OrderedBulk .delete_one (%{kind: " cat" })
1082
1090
1083
- result = Mongo .BulkWrite .write (:mongo , bulk, w: 1 )
1091
+ result = Mongo .BulkWrite .write (@topology , bulk, w: 1 )
1084
1092
```
1085
1093
1086
1094
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()
1214
1222
iex> {:ok , conn} = Mongo .start_link (url: " mongodb://localhost:27017/test" )
1215
1223
{:ok , # PID<0.226.0>}
1216
1224
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 , .. .
1219
1227
```
1220
1228
1221
1229
## Testing
0 commit comments