mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
added MongoCursor::getQuery and recursive warning
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@295967 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
37894faed3
commit
a33cd08aca
4 changed files with 157 additions and 63 deletions
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section xml:id="mongo.datatypes" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Data Types</title>
|
||||
|
||||
</section>
|
||||
|
||||
<!-- 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
|
||||
indent-tabs-mode:nil
|
||||
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
|
||||
-->
|
93
reference/mongo/mongocursor/getquery.xml
Normal file
93
reference/mongo/mongocursor/getquery.xml
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongocursor.getquery" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>MongoCursor::getQuery</refname>
|
||||
<refpurpose>Gets the query, fields, limit, and skip for this cursor</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>array</type><methodname>MongoCursor::getQuery</methodname>
|
||||
<void/>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
This can be called before or after the query.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
&no.function.parameters;
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
The query, fields, limit, and skip for this cursor as an associative array.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<example>
|
||||
<title><function>MongoCursor::getQuery</function> example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$m = new Mongo();
|
||||
$cursor = $m->foo->bar->find(array("x" => 4), array("y" => false));
|
||||
var_dump($cursor->getQuery());
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs.similar;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
array(5) {
|
||||
["ns"]=>
|
||||
string(7) "foo.bar"
|
||||
["limit"]=>
|
||||
int(0)
|
||||
["skip"]=>
|
||||
int(0)
|
||||
["query"]=>
|
||||
array(1) {
|
||||
["x"]=>
|
||||
int(4)
|
||||
}
|
||||
["fields"]=>
|
||||
array(1) {
|
||||
["y"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</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
|
||||
-->
|
|
@ -14,37 +14,6 @@
|
|||
a half-dozen classes provided by the MongoDB PHP driver (for regular
|
||||
expressions, dates, and other specialized applications).
|
||||
</para>
|
||||
<para>
|
||||
MongoDB uses a storage format called "BSON," Binary Serializable Object
|
||||
Notation, which is similar to JSON but more compact and rich in types. Listed
|
||||
below is the exact byte size of each type (or information required to compute
|
||||
its size, in the case of variable-length types). Keep in mind that these
|
||||
sizes do not include field names. The size of an object can be manually
|
||||
computed, but it may be easier for programmers to call the
|
||||
<function>bson_encode</function> function and take the length of the resulting
|
||||
string.
|
||||
</para>
|
||||
<para>
|
||||
An example of manually computing BSON size for saving the object
|
||||
array("x" => null, "y" => 40):
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
4 bytes (object size)
|
||||
|
||||
1 byte (type of "x" field)
|
||||
2 bytes ("x" and "\0")
|
||||
0 bytes (for null)
|
||||
|
||||
1 byte (type of "y" field)
|
||||
2 bytes ("y" and "\0")
|
||||
4 bytes (for an integer)
|
||||
|
||||
1 byte (end-of-object byte)
|
||||
-----------------------
|
||||
15 bytes
|
||||
]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
@ -107,9 +76,9 @@
|
|||
<![CDATA[
|
||||
<?php
|
||||
|
||||
// $scores will be saved as an array
|
||||
$scores = array(98, 100, 73, 85);
|
||||
$collection->insert(array("scores" => $scores);
|
||||
// $scores will be saved as an array
|
||||
$scores = array(98, 100, 73, 85);
|
||||
$collection->insert(array("scores" => $scores);
|
||||
|
||||
// $scores will be saved as an object
|
||||
$scores = array("quiz1" => 98, "midterm" => 100, "quiz2" => 73, "final" => 85);
|
||||
|
@ -181,13 +150,36 @@ $blog->insert($post2);
|
|||
<para>
|
||||
From the database shell, this will look something like:
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
> db.blog.find()
|
||||
{ "_id" : ObjectId("4b06c263edb87a281e09dad8"), "author" : "Adam", "content" : "This is a blog post", "comments" : [ ], "date" : "Fri Nov 20 2009 11:22:59 GMT-0500 (EST)" }
|
||||
{ "_id" : ObjectId("4b06c282edb87a281e09dad9"), "author" : { "name" : "Fred", "karma" : 42 }, "content" : "This is a blog post", "comments" : [ ], "date" : "Fri Nov 20 2009 11:23:30 GMT-0500 (EST)", "title" : "Second Post" }
|
||||
]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The driver will not detect reference loops in arrays and objects. For
|
||||
example, this will give a fatal error:
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$collection->insert($GLOBALS);
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
|
||||
Fatal error: Nesting level too deep - recursive dependency?
|
||||
|
||||
]]>
|
||||
</programlisting>
|
||||
If you need to insert documents that may have recursive dependency, you have
|
||||
to check for it yourself before passing it to the driver.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
@ -321,6 +313,42 @@ $blog->insert($post2);
|
|||
</informaltable>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>BSON</title>
|
||||
<para>
|
||||
MongoDB uses a storage format called "BSON," Binary Serializable Object
|
||||
Notation, which is similar to JSON but more compact and rich in types. Listed
|
||||
below is the exact byte size of each type (or information required to compute
|
||||
its size, in the case of variable-length types). Keep in mind that these
|
||||
sizes do not include field names. The size of an object can be manually
|
||||
computed, but it may be easier for programmers to call the
|
||||
<function>bson_encode</function> function and take the length of the resulting
|
||||
string.
|
||||
</para>
|
||||
<para>
|
||||
An example of manually computing BSON size for saving the object
|
||||
array("x" => null, "y" => 40):
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
4 bytes (object size)
|
||||
|
||||
1 byte (type of "x" field)
|
||||
2 bytes ("x" and "\0")
|
||||
0 bytes (for null)
|
||||
|
||||
1 byte (type of "y" field)
|
||||
2 bytes ("y" and "\0")
|
||||
4 bytes (for an integer)
|
||||
|
||||
1 byte (end-of-object byte)
|
||||
-----------------------
|
||||
15 bytes
|
||||
]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</partintro>
|
||||
|
||||
&reference.mongo.mongoid;
|
||||
|
|
|
@ -89,6 +89,7 @@
|
|||
<function name='mongocursor::dead' from='PECL mongo >=0.9.6'/>
|
||||
<function name='mongocursor::immortal' from='PECL mongo >=1.0.1'/>
|
||||
<function name='mongocursor::addoption' from='PECL mongo >=1.0.4'/>
|
||||
<function name='mongocursor::getquery' from='PECL mongo >=1.0.5'/>
|
||||
<!-- MongoGridFS -->
|
||||
<function name='mongogridfs::__construct' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongogridfs::find' from='PECL mongo >=0.9.0'/>
|
||||
|
|
Loading…
Reference in a new issue