<!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>Executes the command and resets the cursor to the start of the result set</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongocommandcursor.next.html">MongoCommandCursor::next</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongocommandcursor.setreadpreference.html">MongoCommandCursor::setReadPreference</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.rewind" class="refentry"> <div class="refnamediv"> <h1 class="refname">MongoCommandCursor::rewind</h1> <p class="verinfo">(PECL mongo >=1.5.0)</p><p class="refpurpose"><span class="refname">MongoCommandCursor::rewind</span> — <span class="dc-title">Executes the command and resets the cursor to the start of the result set</span></p> </div> <div class="refsect1 description" id="refsect1-mongocommandcursor.rewind-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">array</span> <span class="methodname"><strong>MongoCommandCursor::rewind</strong></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> If the cursor has already started iteration, the command will be re-executed. </p> </div> <div class="refsect1 parameters" id="refsect1-mongocommandcursor.rewind-parameters"> <h3 class="title">Parameters</h3> <p class="para">This function has no parameters.</p> </div> <div class="refsect1 returnvalues" id="refsect1-mongocommandcursor.rewind-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The raw server result document. </p> </div> <div class="refsect1 errors" id="refsect1-mongocommandcursor.rewind-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> Throws <a href="class.mongoconnectionexception.html" class="classname">MongoConnectionException</a> if it cannot reach the database and <a href="class.mongocursortimeoutexception.html" class="classname">MongoCursorTimeoutException</a> if the timeout is exceeded. </p> <p class="para"> Throws <a href="class.mongocursorexception.html" class="classname">MongoCursorException</a> if the cursor was created with <span class="function"><a href="mongocommandcursor.createfromdocument.html" class="function">MongoCommandCursor::createFromDocument()</a></span> and has already started iteration. Such cursors cannot be iterated multiple times, as they lack the original command necessary for re-execution. </p> </div> <div class="refsect1 examples" id="refsect1-mongocommandcursor.rewind-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-1638"> <p><strong>Example #1 <span class="function"><strong>MongoCommandCursor::rewind()</strong></span></strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$rawResult </span><span style="color: #007700">= </span><span style="color: #0000BB">$commandCursor</span><span style="color: #007700">-></span><span style="color: #0000BB">rewind</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Command cursor is now reset to the start of the result set<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$rawResult</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> array(2) { ["cursor"]=> array(3) { ["id"]=> object(MongoInt64)#5 (1) { ["value"]=> string(12) "310050110216" } ["ns"]=> string(9) "demo.test" ["firstBatch"]=> array(1) { [0]=> array(2) { ["_id"]=> object(MongoId)#6 (1) { ["$id"]=> string(24) "52f5691544670a8077b0dc51" } ["value"]=> string(2) "42" } } } ["ok"]=> float(1) } </pre></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-mongocommandcursor.rewind-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"><span class="methodname"><a href="iterator.rewind.html" class="methodname" rel="rdfs-seeAlso">Iterator::rewind()</a> - Rewind the Iterator to the first element</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.next.html">MongoCommandCursor::next</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongocommandcursor.setreadpreference.html">MongoCommandCursor::setReadPreference</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>