Skip to content

Commit

Permalink
chore: add documentation how to set the read preference
Browse files Browse the repository at this point in the history
  • Loading branch information
zookzook committed Jul 30, 2023
1 parent d7cb466 commit 1137acc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,27 @@ Mongo.find(conn, "dogs", %{}, timeout: 120_000)

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

## Read Preferences

The `:read_preference` option sets [read preference](https://www.mongodb.com/docs/manual/core/read-preference/) for the query. The read preference is
a simple map, supporting the following keys:

* `:mode`, possible values: `:primary`, `:primary_preferred`, `:secondary`, `:secondary_preferred` and `:nearest`
* `:max_staleness_ms`, the maxStaleness value in milliseconds
* `:tag_sets`, the set of tags, for example: `[dc: "west", usage: "production"]`

The driver selects the server using the read preference.

```elixr
prefs = %{
mode: :secondary,
max_staleness_ms: 120_000,
tag_sets: [dc: "west", usage: "production"]
}
Mongo.find_one(top, "dogs", %{name: "Oskar"}, read_preference: prefs)
```

## Change Streams

Change streams are available in replica set and sharded cluster deployments
Expand Down

0 comments on commit 1137acc

Please sign in to comment.