> This page location: /docs.md > /docs/drivers.md > /docs/languages/ruby.md > /docs/ruby-driver/current.md > /docs/ruby-driver/current/connect/connection-options.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# Server Selection

## Overview

The MongoDB Ruby Driver follows a defined algorithm or the read preference defined in the client options when selecting a server to read or write from.

## Server Selection Algorithm

When the Ruby driver executes a read operation, it performs the following steps, in order, to select a MongoDB deployment:

1. From the list of known servers, the Ruby driver selects all servers that match the active read preference.

2. The Ruby driver removes any server from the list that doesn't meet the `localThresholdMS` connection setting criteria, and returns the updated list.

3. The Ruby driver selects a server at random from the servers still on the list and executes the operation against this server.

When the Ruby driver executes a write operation, it begins by selecting all writeable servers, not just those that match the active read preference. The remaining steps are identical.

To learn more about the server-selection algorithm, see the [Server Selection Algorithm](https://www.mongodb.com/docs/manual/core/read-preference-mechanics/) in the MongoDB Server manual.

## Customize Server Selection

For replica sets, you can select a read preference to determine which member the Ruby driver reads from. For more information about how to configure a read preference, see the [Read Preference](https://www.mongodb.com/docs/ruby-driver/current/crud/configure-crud.md#std-label-ruby-read-pref) section of the Configure CRUD Operations guide.

## API Documentation

For more information about the Ruby driver's server-selection algorithm, see the following API documentation:

- [Mongo::Client](https://www.mongodb.com/docs/ruby-driver/current/api/Mongo/Client.html#server_selector-instance_method)

- [Server::Description](https://www.mongodb.com/docs/ruby-driver/current/api/Mongo/Server/Description.html)
