php-doc-en/reference/mongo/mongocommandcursor/createfromdocument.xml
Hannes Magnusson daf331850e s/MongoDB:command/MongoDB::command/g
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@335865 c90b9560-bf6c-de11-be94-00142212c4b1
2015-02-03 01:02:43 +00:00

182 lines
4.6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongocommandcursor.createfromdocument" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoCommandCursor::createFromDocument</refname>
<refpurpose>Create a new command cursor from an existing command response document</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>MongoCommandCursor</type><methodname>MongoCommandCursor::createFromDocument</methodname>
<methodparam><type>MongoClient</type><parameter>connection</parameter></methodparam>
<methodparam><type>string</type><parameter>hash</parameter></methodparam>
<methodparam><type>array</type><parameter>document</parameter></methodparam>
</methodsynopsis>
<para>
Use this method if you have a raw command result with cursor information in
it. Note that cursors created with this method cannot be iterated multiple
times, as they will lack the original command necessary for re-execution.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term>
<parameter>connection</parameter>
</term>
<listitem>
<para>
Database connection.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>hash</parameter>
</term>
<listitem>
<para>
The connection hash, as obtained through the third by-reference argument
to <methodname>MongoDB::command</methodname>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>document</parameter>
</term>
<listitem>
<para>
Document with cursor information in it. This document needs to contain
the <literal>id</literal>, <literal>ns</literal> and
<literal>firstBatch</literal> fields. Such a document is obtained by
calling the <methodname>MongoDB::command</methodname> with appropriate
arguments to return a cursor, and not just an inline result. See the
example below.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the new cursor.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoCommandCursor::createFromDocument</function></title>
<programlisting role="php">
<![CDATA[
<?php
$m = new MongoClient;
$d = $m->demo;
// Define the aggregation pipeline
$pipeline = [
[ '$group' => [
'_id' => '$country_code',
'timezones' => [ '$addToSet' => '$timezone' ]
] ],
[ '$sort' => [ '_id' => 1 ] ],
];
// Execute the command. The "cursor" option instructs the server to return
// cursor information in the response instead of inline results.
$r = $d->command(
[
'aggregate' => 'cities',
'pipeline' => $pipeline,
'cursor' => [ 'batchSize' => 1 ],
],
null,
$hash
);
// Show result and hash
var_dump( $r, $hash );
// Construct the command cursor
$cursor = MongoCommandCursor::createFromDocument( $m, $hash, $r );
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
array(2) {
["cursor"]=>
array(3) {
["id"]=>
object(MongoInt64)#5 (1) {
["value"]=>
string(12) "392143983421"
}
["ns"]=>
string(11) "demo.cities"
["firstBatch"]=>
array(1) {
[0]=>
array(2) {
["_id"]=>
string(2) "AD"
["timezones"]=>
array(1) {
[0]=>
string(14) "Europe/Andorra"
}
}
}
}
["ok"]=>
float(1)
}
string(25) "localhost:27017;-;.;17617"
]]>
</screen>
<para>
As you can see, the returned cursor information has the
<literal>id</literal>, <literal>ns</literal> and
<literal>firstBatch</literal> fields.
</para>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>MongoCommandCursor::__construct</function></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
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
-->