Skip to content

Commit 1137acc

Browse files
committed
chore: add documentation how to set the read preference
1 parent d7cb466 commit 1137acc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,27 @@ Mongo.find(conn, "dogs", %{}, timeout: 120_000)
746746

747747
Now the driver will use 120 seconds as the timeout for the single query.
748748

749+
## Read Preferences
750+
751+
The `:read_preference` option sets [read preference](https://www.mongodb.com/docs/manual/core/read-preference/) for the query. The read preference is
752+
a simple map, supporting the following keys:
753+
754+
* `:mode`, possible values: `:primary`, `:primary_preferred`, `:secondary`, `:secondary_preferred` and `:nearest`
755+
* `:max_staleness_ms`, the maxStaleness value in milliseconds
756+
* `:tag_sets`, the set of tags, for example: `[dc: "west", usage: "production"]`
757+
758+
The driver selects the server using the read preference.
759+
760+
```elixr
761+
prefs = %{
762+
mode: :secondary,
763+
max_staleness_ms: 120_000,
764+
tag_sets: [dc: "west", usage: "production"]
765+
}
766+
767+
Mongo.find_one(top, "dogs", %{name: "Oskar"}, read_preference: prefs)
768+
```
769+
749770
## Change Streams
750771

751772
Change streams are available in replica set and sharded cluster deployments

0 commit comments

Comments
 (0)