.\" This manpage is Copyright (C) 2016 MongoDB, Inc. .\" .\" Permission is granted to copy, distribute and/or modify this document .\" under the terms of the GNU Free Documentation License, Version 1.3 .\" or any later version published by the Free Software Foundation; .\" with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. .\" A copy of the license is included in the section entitled "GNU .\" Free Documentation License". .\" .TH "MONGOC_CLIENT_GET_SERVER_DESCRIPTIONS" "3" "2016\(hy10\(hy12" "MongoDB C Driver" .SH NAME mongoc_client_get_server_descriptions() \- None .SH "SYNOPSIS" .nf .nf mongoc_server_description_t ** mongoc_client_get_server_descriptions ( const mongoc_client_t *client, size_t *n); .fi .fi Fetches an array of .B mongoc_server_description_t structs for all known servers in the topology. Returns no servers until the client connects. Returns a single server if the client is directly connected, or all members of a replica set if the client's MongoDB URI includes a "replicaSet" option, or all known mongos servers if the MongoDB URI includes a list of them. .nf void show_servers (const mongoc_client_t *client) { bson_t *b = BCON_NEW ("ping", BCON_INT32 (1)); bson_error_t error; bool r; mongoc_server_description_t **sds; size_t i, n; /* ensure client has connected */ r = mongoc_client_command_simple (client, "db", b, NULL, NULL, &error); if (!r) { MONGOC_ERROR ("could not connect: %s\en", error.message); return; } sds = mongoc_client_get_server_descriptions (client, &n); for (i = 0; i < n; ++i) { printf ("%s\en", mongoc_server_description_host (sds[i])\(hy>host_and_port); } mongoc_server_descriptions_destroy_all (sds, n); bson_destroy (&b); } .fi .SH "PARAMETERS" .TP .B client A .B mongoc_client_t . .LP .TP .B n Receives the length of the descriptions array. .LP .SH "RETURNS" A newly allocated array that must be freed with .B mongoc_server_descriptions_destroy_all . .B .SH COLOPHON This page is part of MongoDB C Driver. Please report any bugs at https://jira.mongodb.org/browse/CDRIVER.