<!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>Returns an array of cursors to iterator over a full collection in parallel</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongocollection.insert.html">MongoCollection::insert</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongocollection.remove.html">MongoCollection::remove</a></div> <div class="up"><a href="class.mongocollection.html">MongoCollection</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongocollection.parallelcollectionscan" class="refentry"> <div class="refnamediv"> <h1 class="refname">MongoCollection::parallelCollectionScan</h1> <p class="verinfo">(PECL mongo >=1.5.0)</p><p class="refpurpose"><span class="refname">MongoCollection::parallelCollectionScan</span> — <span class="dc-title">Returns an array of cursors to iterator over a full collection in parallel</span></p> </div> <div class="refsect1 description" id="refsect1-mongocollection.parallelcollectionscan-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type"><span class="type array[MongoCommandCursor]">array[MongoCommandCursor]</span></span> <span class="methodname"><strong>MongoCollection::parallelCollectionScan</strong></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$num_cursors</code></span> )</div> <p class="para rdfs-comment"> This method returns an array of a maximum of <em>num_cursors</em> cursors. An iteration over one of the returned cursors results in a partial set of documents for a collection. Iteration over all the returned cursors results in getting every document back from the collection. </p> <p class="para"> This method is a wrapper for the <em>parallelCollectionScan</em> MongoDB command. </p> </div> <div class="refsect1 parameters" id="refsect1-mongocollection.parallelcollectionscan-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">num_cursors</code> </dt> <dd> <p class="para"> The number of cursors to request from the server. Please note, that the server can return less cursors than you requested. </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-mongocollection.parallelcollectionscan-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an array of <a href="class.mongocommandcursor.html" class="classname">MongoCommandCursor</a> objects. </p> </div> <div class="refsect1 examples" id="refsect1-mongocollection.parallelcollectionscan-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-1603"> <p><strong>Example #1 <span class="function"><strong>MongoCollection::parallelCollectionScan()</strong></span> example</strong></p> <div class="example-contents"><p> Returning all documents in a collection by using multiple cursors. </p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$m </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$c </span><span style="color: #007700">= </span><span style="color: #0000BB">$m</span><span style="color: #007700">-></span><span style="color: #0000BB">demo</span><span style="color: #007700">-></span><span style="color: #0000BB">cities</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* Request three cursors */<br /></span><span style="color: #0000BB">$cursors </span><span style="color: #007700">= </span><span style="color: #0000BB">$c</span><span style="color: #007700">-></span><span style="color: #0000BB">parallelCollectionScan</span><span style="color: #007700">( </span><span style="color: #0000BB">3 </span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Add all the cursors to the MultipleIterator */<br /></span><span style="color: #0000BB">$mi </span><span style="color: #007700">= new </span><span style="color: #0000BB">MultipleIterator</span><span style="color: #007700">( </span><span style="color: #0000BB">MultipleIterator</span><span style="color: #007700">::</span><span style="color: #0000BB">MIT_NEED_ANY </span><span style="color: #007700">);<br />foreach ( </span><span style="color: #0000BB">$cursors </span><span style="color: #007700">as </span><span style="color: #0000BB">$cursor </span><span style="color: #007700">)<br />{<br /> </span><span style="color: #0000BB">$mi</span><span style="color: #007700">-></span><span style="color: #0000BB">attachIterator</span><span style="color: #007700">( </span><span style="color: #0000BB">$cursor </span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">/* Iterate over all the associated cursors */<br /></span><span style="color: #007700">foreach ( </span><span style="color: #0000BB">$mi </span><span style="color: #007700">as </span><span style="color: #0000BB">$items </span><span style="color: #007700">)<br />{<br /> foreach ( </span><span style="color: #0000BB">$items </span><span style="color: #007700">as </span><span style="color: #0000BB">$item </span><span style="color: #007700">)<br /> {<br /> if ( </span><span style="color: #0000BB">$item </span><span style="color: #007700">!== </span><span style="color: #0000BB">NULL </span><span style="color: #007700">)<br /> {<br /> echo </span><span style="color: #0000BB">$item</span><span style="color: #007700">[</span><span style="color: #DD0000">'name'</span><span style="color: #007700">], </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /> }<br /> }<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-mongocollection.parallelcollectionscan-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="class.multipleiterator.html" class="classname">MultipleIterator</a></li> <li class="member"><a href="class.mongocommandcursor.html" class="classname">MongoCommandCursor</a></li> <li class="member"><span class="methodname"><a href="mongodb.command.html" class="methodname" rel="rdfs-seeAlso">MongoDB::command()</a> - Execute a database command</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongocollection.insert.html">MongoCollection::insert</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongocollection.remove.html">MongoCollection::remove</a></div> <div class="up"><a href="class.mongocollection.html">MongoCollection</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>