Skip site navigation (1)Skip section navigation (2)

  
 
  

home | help
MONGOC_CLIENT...R_DESCRIPTIONS(3)   libmongoc  MONGOC_CLIENT...R_DESCRIPTIONS(3)

SYNOPSIS
	mongoc_server_description_t **
	mongoc_client_get_server_descriptions (const mongoc_client_t *client,
					       size_t *n);

     Fetches  an  array  of  mongoc_server_description_t  structs  for all known
     servers in the topology. Returns no servers until the client connects.  Re-
     turns  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"  op-
     tion,  or	all  known  mongos servers if the MongoDB URI includes a list of
     them.

	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\n", error.message);
	      return;
	   }

	   sds = mongoc_client_get_server_descriptions (client, &n);

	   for (i = 0; i < n; ++i) {
	      printf ("%s\n", mongoc_server_description_host (sds[i])->host_and_port);
	   }

	   mongoc_server_descriptions_destroy_all (sds, n);
	   bson_destroy (&b);
	}

PARAMETERS
     * client: A mongoc_client_t.

     * n: Receives the length of the descriptions array.

RETURNS
     A	  newly    allocated	array	 that	  must	   be	  freed     with
     mongoc_server_descriptions_destroy_all().

AUTHOR
     MongoDB, Inc

COPYRIGHT
     2009-present, MongoDB, Inc.

1.30.8				  Aug 27, 2026 MONGOC_CLIENT...R_DESCRIPTIONS(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=mongoc_client_get_server_descriptions&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help