Skip to content

Commit 0dcddb7

Browse files
committed
added documentation to create indexes
1 parent 71cca55 commit 0dcddb7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,21 @@ Mongo.insert_many(top, "users", [
270270
])
271271
```
272272

273+
### Indexes
274+
275+
To create indexes you can call the function `Mongo.createIndexed/4`:
276+
277+
```elixir
278+
indexes = [[key: [files_id: 1, n: 1], name: "files_n_index", unique: true]]
279+
Mongo.create_indexes(topology_pid, "my_collection", indexes, opts)
280+
```
281+
282+
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.
283+
284+
For more information see:
285+
* [Mongo.create_indexes](https://hexdocs.pm/mongodb_driver/Mongo.html#create_indexes/4)
286+
* [Mongo.drop_index](https://hexdocs.pm/mongodb_driver/Mongo.html#drop_index/4)
287+
273288
### Bulk Writes
274289

275290
The motivation for bulk writes lies in the possibility of optimization, the same operations

lib/mongo.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,10 @@ defmodule Mongo do
11941194
end
11951195

11961196
@doc """
1197-
Convenient function to creates new indexes in the collection `coll`.
1197+
Convenient function to creates new indexes in the collection `coll`. The `indexes` parameter
1198+
is a keyword list with all options for creating indexes in the MongoDB.
1199+
See [options](https://docs.mongodb.com/manual/reference/command/createIndexes/#dbcmd.createIndexes) about the
1200+
details of each parameter.
11981201
"""
11991202
@spec create_indexes(GenServer.server, String.t, Keyword.t, Keyword.t) :: :ok | {:error, Mongo.Error.t}
12001203
def create_indexes(topology_pid, coll, indexes, opts \\ []) do

0 commit comments

Comments
 (0)