<!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>Create a new command cursor</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongocommandcursor.batchsize.html">MongoCommandCursor::batchSize</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongocommandcursor.createfromdocument.html">MongoCommandCursor::createFromDocument</a></div> <div class="up"><a href="class.mongocommandcursor.html">MongoCommandCursor</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongocommandcursor.construct" class="refentry"> <div class="refnamediv"> <h1 class="refname">MongoCommandCursor::__construct</h1> <p class="verinfo">(PECL mongo >=1.5.0)</p><p class="refpurpose"><span class="refname">MongoCommandCursor::__construct</span> — <span class="dc-title">Create a new command cursor</span></p> </div> <div class="refsect1 description" id="refsect1-mongocommandcursor.construct-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><strong>MongoCommandCursor::__construct</strong></span> ( <span class="methodparam"><span class="type"><a href="class.mongoclient.html" class="type MongoClient">MongoClient</a></span> <code class="parameter">$connection</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$ns</code></span> , <span class="methodparam"><span class="type">array</span> <code class="parameter">$command</code><span class="initializer"> = array()</span></span> )</div> <p class="para rdfs-comment"> Generally, you should not have to construct a <a href="class.mongocommandcursor.html" class="classname">MongoCommandCursor</a> manually, as there are helper functions such as <span class="methodname"><a href="mongocollection.aggregatecursor.html" class="methodname">MongoCollection::aggregateCursor()</a></span> and <span class="methodname"><a href="mongocollection.parallelcollectionscan.html" class="methodname">MongoCollection::parallelCollectionScan()</a></span>; however, if the server introduces new commands that can return cursors, this constructor will be useful in the absence of specific helper methods. You may also consider using <span class="methodname"><a href="mongocommandcursor.createfromdocument.html" class="methodname">MongoCommandCursor::createFromDocument()</a></span>. </p> </div> <div class="refsect1 parameters" id="refsect1-mongocommandcursor.construct-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">connection</code> </dt> <dd> <p class="para"> Database connection. </p> </dd> <dt> <code class="parameter">ns</code> </dt> <dd> <p class="para"> Full name of the database and collection (e.g. <em>"test.foo"</em>) </p> </dd> <dt> <code class="parameter">command</code> </dt> <dd> <p class="para"> Database command. </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-mongocommandcursor.construct-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the new cursor. </p> </div> <div class="refsect1 examples" id="refsect1-mongocommandcursor.construct-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-1634"> <p><strong>Example #1 <a href="class.mongocommandcursor.html" class="classname">MongoCommandCursor</a> example</strong></p> <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 /><br /></span><span style="color: #FF8000">// Define the aggregation pipeline<br /></span><span style="color: #0000BB">$pipeline </span><span style="color: #007700">= [<br /> [ </span><span style="color: #DD0000">'$group' </span><span style="color: #007700">=> [<br /> </span><span style="color: #DD0000">'_id' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'$country_code'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'timezones' </span><span style="color: #007700">=> [ </span><span style="color: #DD0000">'$addToSet' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'$timezone' </span><span style="color: #007700">]<br /> ] ],<br /> [ </span><span style="color: #DD0000">'$sort' </span><span style="color: #007700">=> [ </span><span style="color: #DD0000">'_id' </span><span style="color: #007700">=> </span><span style="color: #0000BB">1 </span><span style="color: #007700">] ],<br />];<br /><br /></span><span style="color: #FF8000">// Construct a MongoCommandCursor object<br /></span><span style="color: #0000BB">$cursor </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoCommandCursor</span><span style="color: #007700">(<br /> </span><span style="color: #0000BB">$m</span><span style="color: #007700">, </span><span style="color: #FF8000">// MongoClient object<br /> </span><span style="color: #DD0000">'demo.cities'</span><span style="color: #007700">, </span><span style="color: #FF8000">// namespace<br /> </span><span style="color: #007700">[<br /> </span><span style="color: #DD0000">'aggregate' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'cities'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'pipeline' </span><span style="color: #007700">=> </span><span style="color: #0000BB">$pipeline</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'cursor' </span><span style="color: #007700">=> [ </span><span style="color: #DD0000">'batchSize' </span><span style="color: #007700">=> </span><span style="color: #0000BB">0 </span><span style="color: #007700">],<br /> ]<br />);<br /><br />foreach(</span><span style="color: #0000BB">$cursor </span><span style="color: #007700">as </span><span style="color: #0000BB">$result</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">…<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-mongocommandcursor.construct-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"><span class="function"><a href="mongocommandcursor.createfromdocument.html" class="function" rel="rdfs-seeAlso">MongoCommandCursor::createFromDocument()</a> - Create a new command cursor from an existing command response document</span></li> <li class="member"><span class="function"><a href="mongocollection.aggregatecursor.html" class="function" rel="rdfs-seeAlso">MongoCollection::aggregateCursor()</a> - Execute an aggregation pipeline command and retrieve results through a cursor</span></li> <li class="member"><span class="function"><a href="mongocollection.parallelcollectionscan.html" class="function" rel="rdfs-seeAlso">MongoCollection::parallelCollectionScan()</a> - Returns an array of cursors to iterator over a full collection in parallel</span></li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongocommandcursor.batchsize.html">MongoCommandCursor::batchSize</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongocommandcursor.createfromdocument.html">MongoCommandCursor::createFromDocument</a></div> <div class="up"><a href="class.mongocommandcursor.html">MongoCommandCursor</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>