---
name: "mongoc_client_select_server"
section: "3"
platform: "linux"
package: "libmongoc-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mongoc_client_select_server"
---

# mongoc\_client\_select\_server(3)

## SYNOPSIS

```
mongoc_server_description_t *
mongoc_client_select_server (mongoc_client_t *client,
                             bool for_writes,
                             const mongoc_read_prefs_t *prefs,
                             bson_error_t *error);
```

Choose a server for an operation, according to the logic described in the Server Selection Spec.

Use this function only for building a language driver that wraps the C Driver. When writing applications in C, higher-level functions automatically select a suitable server.

## PARAMETERS

- •

  **client**: A *mongoc\_client\_t*.

- •

  **for\_writes**: Whether to choose a server suitable for writes or reads.

- •

  **prefs**: An optional *mongoc\_read\_prefs\_t*. If **for\_writes** is true, **prefs** must be NULL. Otherwise, use **prefs** to customize server selection, or pass NULL to use read preference PRIMARY.

- •

  **error**: An optional location for a *bson\_error\_t* or **NULL**.

## RETURNS

A *mongoc\_server\_description\_t* that must be freed with *mongoc\_server\_description\_destroy()*. If no suitable server is found, returns NULL and **error** is filled out.

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
