<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Sharding</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongo.connecting.rs.html">Replica Sets</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongo.connecting.uds.html">Domain Socket Support</a></div> <div class="up"><a href="mongo.connecting.html">Connecting</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongo.connecting.mongos" class="section"> <h2 class="title">Sharding</h2> <p class="para"> To connect to a shard cluster, specify the address of one or more <em>mongos</em> instances in the connection string. Multiple servers may be delimited by a comma. </p> <div class="example" id="mongo.connecting.mongos-example"> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Using one server as the seed list<br /></span><span style="color: #0000BB">$m </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://mongos1.example.com:27017"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Using multiple servers as the seed list<br /></span><span style="color: #0000BB">$m </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://mongos1.example.com:27017,mongos2.example.com:27017"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <p class="para"> Regardless of whether each shard is a stand-alone <em>mongod</em> server or a full replica set, the driver's connection process is the same. All database communication will be routed through <em>mongos</em>. </p> <p class="para"> For more information on sharding with MongoDB, see the <a href="http://docs.mongodb.org/manual/sharding/" class="link external">» sharding documentation</a>. </p> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongo.connecting.rs.html">Replica Sets</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongo.connecting.uds.html">Domain Socket Support</a></div> <div class="up"><a href="mongo.connecting.html">Connecting</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>