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

NAME

6       mongoc_client_get_server_descriptions               -              mon‐
7       goc_client_get_server_descriptions()
8

SYNOPSIS

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

PARAMETERS

48       · client: A mongoc_client_t.
49
50       · n: Receives the length of the descriptions array.
51

RETURNS

53       A  newly allocated array that must be freed with mongoc_server_descrip‐
54       tions_destroy_all.
55

AUTHOR

57       MongoDB, Inc
58
60       2017-present, MongoDB, Inc
61
62
63
64
651.16.2                           Feb 25M,ON2G0O2C0_CLIENT_GET_SERVER_DESCRIPTIONS(3)
Impressum