1MONGOC_CLIENT_GET_SERVER_DESCRIPTIONlSi(b3mM)oOnNgGoOcC_CLIENT_GET_SERVER_DESCRIPTIONS(3)
2
3
4

SYNOPSIS

6          mongoc_server_description_t **
7          mongoc_client_get_server_descriptions (const mongoc_client_t *client,
8                                                 size_t *n) BSON_GNUC_WARN_UNUSED_RESULT;
9
10       Fetches  an  array of mongoc_server_description_t structs for all known
11       servers in the topology. Returns no servers until the client  connects.
12       Returns  a  single  server  if the client is directly connected, or all
13       members of a replica set if the client's MongoDB URI includes a "repli‐
14       caSet"  option, or all known mongos servers if the MongoDB URI includes
15       a list of them.
16
17          void
18          show_servers (const mongoc_client_t *client)
19          {
20             bson_t *b = BCON_NEW ("ping", BCON_INT32 (1));
21             bson_error_t error;
22             bool r;
23             mongoc_server_description_t **sds;
24             size_t i, n;
25
26             /* ensure client has connected */
27             r = mongoc_client_command_simple (client, "db", b, NULL, NULL, &error);
28             if (!r) {
29                MONGOC_ERROR ("could not connect: %s\n", error.message);
30                return;
31             }
32
33             sds = mongoc_client_get_server_descriptions (client, &n);
34
35             for (i = 0; i < n; ++i) {
36                printf ("%s\n", mongoc_server_description_host (sds[i])->host_and_port);
37             }
38
39             mongoc_server_descriptions_destroy_all (sds, n);
40             bson_destroy (&b);
41          }
42

PARAMETERS

44client: A mongoc_client_t.
45
46n: Receives the length of the descriptions array.
47

RETURNS

49       A    newly    allocated    array    that    must    be    freed    with
50       mongoc_server_descriptions_destroy_all().
51

AUTHOR

53       MongoDB, Inc
54
56       2017-present, MongoDB, Inc
57
58
59
60
611.25.1                           Nov 08M,ON2G0O2C3_CLIENT_GET_SERVER_DESCRIPTIONS(3)
Impressum