<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="mongodb-driver-manager.selectserver" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>MongoDB\Driver\Manager::selectServer</refname>
  <refpurpose>Select a server matching a read preference</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <modifier>final</modifier> <modifier>public</modifier> <type>MongoDB\Driver\Server</type><methodname>MongoDB\Driver\Manager::selectServer</methodname>
   <methodparam choice="opt"><type class="union"><type>MongoDB\Driver\ReadPreference</type><type>null</type></type><parameter>readPreference</parameter><initializer>&null;</initializer></methodparam>
  </methodsynopsis>
  <para>
   Selects a <classname>MongoDB\Driver\Server</classname> matching
   <parameter>readPreference</parameter>. If
   <parameter>readPreference</parameter> is &null; or omitted, the primary
   server will be selected by default. This may be used to preselect a server in
   order to perform version checking before executing an operation.
  </para>
  <note>
   <simpara>
    Unlike <function>MongoDB\Driver\Manager::getServers</function>, this method
    will initialize database connections and perform server discovery if
    necessary. See the
    <link xlink:href="&url.mongodb.serverselection;#single-threaded-server-selection">Server Selection Specification</link>
    for additional information.
   </simpara>
  </note>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <variablelist>
   <varlistentry>
    <term><parameter>readPreference</parameter> (<classname>MongoDB\Driver\ReadPreference</classname>)</term>
    <listitem>
     <para>
      The read preference to use for selecting a server. If &null; or omitted,
      the primary server will be selected by default.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns a <classname>MongoDB\Driver\Server</classname> matching the read
   preference.
  </para>
 </refsect1>

 <refsect1 role="errors">
  &reftitle.errors;
  <simplelist>
   &mongodb.throws.std;
   <member>Throws <classname>MongoDB\Driver\Exception\RuntimeException</classname> if a server matching the read preference could not be found.</member>
  </simplelist>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>PECL mongodb 1.11.0</entry>
       <entry>
        The <parameter>readPreference</parameter> is now optional. If &null; or
        omitted, the primary server will be selected by default.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <simplelist>
   <member><classname>MongoDB\Driver\Server</classname></member>
   <member><function>MongoDB\Driver\Manager::getServers</function></member>
   <member><link xlink:href="&url.mongodb.serverselection;">Server Selection Specification</link></member>
  </simplelist>
 </refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
