mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
- Updated the install structure to be consistent with all other extensions
- Updated the markup in the tutorial to mark examples as such - Gave IDs to all the tutorial sections to split them down into individual pages for readability git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@328517 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
039bd1d774
commit
a90f5b7e51
14 changed files with 262 additions and 116 deletions
|
@ -7,12 +7,15 @@
|
|||
<title>MongoDB Native Driver</title>
|
||||
<titleabbrev>Mongo</titleabbrev>
|
||||
|
||||
&reference.mongo.setup;
|
||||
<!-- &reference.mongo.constants; -->
|
||||
|
||||
&reference.mongo.manual;
|
||||
&reference.mongo.core;
|
||||
&reference.mongo.types;
|
||||
&reference.mongo.gridfs;
|
||||
&reference.mongo.misc;
|
||||
&reference.mongo.functions;
|
||||
&reference.mongo.reference;
|
||||
&reference.mongo.exceptions;
|
||||
|
||||
<appendix xmlns="http://docbook.org/ns/docbook" xml:id="changelog.mongo">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section xml:id="mongo.connecting" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<chapter xml:id="mongo.connecting" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Connecting</title>
|
||||
|
||||
<para>
|
||||
|
@ -359,4 +359,25 @@ for ($i=0; $i<1000; $i++) {
|
|||
</para>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
<!-- 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
|
||||
-->
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<part xml:id="mongo.functions" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
|
||||
<title>Functions</title>
|
||||
|
||||
&reference.mongo.reference;
|
||||
|
||||
</part>
|
|
@ -1,16 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<chapter xml:id="mongo.manual" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<part xml:id="mongo.manual" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Manual</title>
|
||||
<para>
|
||||
This manual goes into some detail about how to use MongoDB, but it mostly
|
||||
covers using the PHP driver. For information about how to design a
|
||||
schema, what terms means, and setting up the database server, check out the
|
||||
<link xlink:href="&url.mongodb;">MongoDB documentation</link>.
|
||||
</para>
|
||||
<partintro xml:id="mongo.manual.intro">
|
||||
<para>
|
||||
This manual goes into some detail about how to use MongoDB, but it mostly
|
||||
covers using the PHP driver. For information about how to design a
|
||||
schema, what terms means, and setting up the database server, check out the
|
||||
<link xlink:href="&url.mongodb;">MongoDB documentation</link>.
|
||||
</para>
|
||||
</partintro>
|
||||
|
||||
&reference.mongo.configure;
|
||||
&reference.mongo.tutorial;
|
||||
&reference.mongo.sqltomongo;
|
||||
&reference.mongo.connecting;
|
||||
|
@ -18,12 +19,11 @@
|
|||
&reference.mongo.writes;
|
||||
&reference.mongo.queries;
|
||||
&reference.mongo.updates;
|
||||
&reference.mongo.ini;
|
||||
&reference.mongo.security;
|
||||
&reference.mongo.trouble;
|
||||
&reference.mongo.testing;
|
||||
|
||||
</chapter>
|
||||
</part>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
<section xml:id="mongo.queries" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<chapter xml:id="mongo.queries" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Querying</title>
|
||||
|
||||
<section>
|
||||
|
@ -300,7 +300,7 @@ $cursor = $collection->find(array("awards" => array('$in' => array("gold", "copp
|
|||
</programlisting>
|
||||
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section xml:id="mongo.readpreferences" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<chapter xml:id="mongo.readpreferences" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Read Preferences</title>
|
||||
<para>
|
||||
MongoDB 2.2 and version 1.3.0 of the driver add support for
|
||||
|
@ -279,4 +279,26 @@ $m->setReadPreference(MongoClient::RP_NEAREST, array(
|
|||
</example>
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
<!-- 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
|
||||
-->
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section xml:id="mongo.security" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<chapter xml:id="mongo.security" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Security</title>
|
||||
|
||||
<section>
|
||||
|
@ -143,7 +143,7 @@ $db->execute(new MongoCode("eval(input);", $scope));
|
|||
user input as code.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
|
|
44
reference/mongo/setup.xml
Normal file
44
reference/mongo/setup.xml
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<chapter xml:id="extname.setup" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
&reftitle.setup;
|
||||
|
||||
<!-- {{{ Requirements -->
|
||||
<section xml:id="extname.requirements">
|
||||
&reftitle.required;
|
||||
&no.requirement;
|
||||
</section>
|
||||
<!-- }}} -->
|
||||
|
||||
<!-- {{{ Installation -->
|
||||
&reference.mongo.configure;
|
||||
<!-- }}} -->
|
||||
|
||||
<!-- {{{ Configuration -->
|
||||
&reference.mongo.ini;
|
||||
<!-- }}} -->
|
||||
|
||||
</chapter>
|
||||
|
||||
<!-- 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
|
||||
-->
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
<section xml:id="mongo.sqltomongo" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<chapter xml:id="mongo.sqltomongo" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>SQL to Mongo Mapping Chart</title>
|
||||
<para>
|
||||
This is a PHP-specific version of the
|
||||
|
@ -230,7 +230,7 @@
|
|||
</tgroup>
|
||||
</informaltable>
|
||||
</para>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section xml:id="mongo.testing" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<chapter xml:id="mongo.testing" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Running the Driver's Tests</title>
|
||||
|
||||
<para>
|
||||
|
@ -96,4 +96,26 @@ $ phpunit tests/MongoSuite.php
|
|||
type testing any functionality.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
<!-- 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
|
||||
-->
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section xml:id="mongo.trouble" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<chapter xml:id="mongo.trouble" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Troubleshooting</title>
|
||||
|
||||
<para>
|
||||
|
@ -60,7 +60,7 @@ $ ./configure CFLAGS=-DDEBUG
|
|||
</itemizedlist>
|
||||
</para>
|
||||
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section xml:id="mongo.tutorial" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<chapter xml:id="mongo.tutorial" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Tutorial</title>
|
||||
<section>
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
This is the 10gen-supported PHP driver for MongoDB.
|
||||
</para>
|
||||
<para>Here's a quick code sample that connects, inserts documents, queries for
|
||||
documents, iterates through query results, and disconnects from MongoDB.
|
||||
There are more details on each step in the tutorial below.
|
||||
</para>
|
||||
<para>
|
||||
This is the 10gen-supported PHP driver for MongoDB.
|
||||
</para>
|
||||
<para>Here's a quick code sample that connects, inserts documents, queries for
|
||||
documents, iterates through query results, and disconnects from MongoDB.
|
||||
There are more details on each step in the tutorial below.
|
||||
</para>
|
||||
<example xml:id="mongo.tutorial.basics">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
@ -44,23 +43,24 @@ foreach ($cursor as $obj) {
|
|||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
This would output:
|
||||
</para>
|
||||
&example.outputs;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Calvin and Hobbes
|
||||
XKCD
|
||||
]]>
|
||||
</screen>
|
||||
</section>
|
||||
<section>
|
||||
</example>
|
||||
|
||||
|
||||
<section xml:id="mongo.tutorial.connecting">
|
||||
<title>Making a Connection</title>
|
||||
<para>
|
||||
To connect to the database server, use one of the following:
|
||||
</para>
|
||||
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.connecting-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -70,13 +70,14 @@ $connection = new MongoClient( "example.com:65432" ); // connect to a remote hos
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
You do not have to explicitly disconnect from the database. When
|
||||
<literal>$connection</literal> goes out of scope, the connection will be
|
||||
closed automatically and any database resources it was using will be freed.
|
||||
</para>
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.connecting.seealso">
|
||||
<title>See Also</title>
|
||||
<para>
|
||||
The chapter on <link linkend="mongo.connecting">connecting</link>
|
||||
|
@ -88,13 +89,15 @@ $connection = new MongoClient( "example.com:65432" ); // connect to a remote hos
|
|||
all possible options with a number of examples.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.selectdb">
|
||||
<title>Getting a Database</title>
|
||||
<para>
|
||||
To select a database, use:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.selectdb-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -102,7 +105,8 @@ $db = $connection->dbname;
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
The database does not need to be created in advance, you can create new
|
||||
databases by selecting them.
|
||||
|
@ -111,7 +115,8 @@ $db = $connection->dbname;
|
|||
Be careful of typos! You can inadvertently create a new database, which can
|
||||
cause confusing errors:
|
||||
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.selectdb.typo">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -122,9 +127,10 @@ $db = $connection->mybiglongdbanme;
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.selectdb.seealso">
|
||||
<title>See Also</title>
|
||||
<para>
|
||||
The API documentation on the <classname>MongoDB</classname> class contains
|
||||
|
@ -133,12 +139,13 @@ $db = $connection->mybiglongdbanme;
|
|||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.collection">
|
||||
<title>Getting A Collection</title>
|
||||
<para>
|
||||
Getting a collection has the same syntax as getting a database:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.collection-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -150,12 +157,13 @@ $collection = $connection->baz->foobar;
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
A collection is analogous to a table (if you are familiar with relational
|
||||
databases).
|
||||
</para>
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.collection.seealso">
|
||||
<title>See Also</title>
|
||||
<para>
|
||||
The API documentation on the <classname>MongoCollection</classname> class
|
||||
|
@ -164,13 +172,14 @@ $collection = $connection->baz->foobar;
|
|||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.insert">
|
||||
<title>Inserting a Document</title>
|
||||
<para>
|
||||
Associative arrays are the basic object that can be saved to a collection in
|
||||
the database. A somewhat random "document" might be:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.insert-data-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -183,14 +192,16 @@ $doc = array( "name" => "MongoDB",
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
Note that you can have nested arrays and objects.
|
||||
</para>
|
||||
<para>
|
||||
To insert this document, use <function>MongoCollection::insert</function>:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.insert-example-2">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -198,8 +209,9 @@ $collection->insert( $doc );
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<section>
|
||||
</programlisting>
|
||||
</example>
|
||||
<section xml:id="mongo.tutorial.insert.seealso">
|
||||
<title>See Also</title>
|
||||
<para>
|
||||
The API documentation on <function>MongoCollection::insert</function>
|
||||
|
@ -208,7 +220,7 @@ $collection->insert( $doc );
|
|||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.findone">
|
||||
<title>
|
||||
Finding Documents using <function>MongoCollection::findOne</function>
|
||||
</title>
|
||||
|
@ -218,7 +230,8 @@ $collection->insert( $doc );
|
|||
single document from the collection. This method is useful when there only is
|
||||
one document matching the query or you are only interested in one result.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.findone-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -227,11 +240,9 @@ var_dump( $obj );
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
This should print:
|
||||
</para>
|
||||
<programlisting>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
array(6) {
|
||||
["_id"]=>
|
||||
|
@ -263,7 +274,8 @@ array(6) {
|
|||
}
|
||||
}
|
||||
]]>
|
||||
</programlisting>
|
||||
</screen>
|
||||
</example>
|
||||
<para>
|
||||
Note that there is an <literal>_id</literal> field that has been added
|
||||
automatically to your document. <literal>_id</literal> is the "primary key"
|
||||
|
@ -274,7 +286,8 @@ array(6) {
|
|||
If you specify your own <literal>_id</literal> field, it must be unique to
|
||||
the collection. See the example here:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.findone-example-2">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -287,7 +300,8 @@ $db->bar->insert(array("_id" => 1), array("safe" => true));
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
Note that these inserts pass a second array:
|
||||
<literal>array("safe" => true)</literal>. This second field specifies
|
||||
|
@ -298,7 +312,7 @@ $db->bar->insert(array("_id" => 1), array("safe" => true));
|
|||
through. In general, all writes should use the "safe" option (it is omitted
|
||||
in previous examples for simplicity).
|
||||
</para>
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.findone.seealso">
|
||||
<title>See Also</title>
|
||||
<para>
|
||||
<function>MongoCollection::findOne</function> for more information about
|
||||
|
@ -317,7 +331,7 @@ $db->bar->insert(array("_id" => 1), array("safe" => true));
|
|||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.insert.multiple">
|
||||
<title>Adding Multiple Documents</title>
|
||||
<para>
|
||||
In order to do more interesting things with queries, let's add multiple
|
||||
|
@ -325,7 +339,8 @@ $db->bar->insert(array("_id" => 1), array("safe" => true));
|
|||
<literal>array( "i" => <replaceable>value</replaceable> );</literal> and we
|
||||
can do this fairly efficiently in a loop:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.insert.multiple-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -335,7 +350,8 @@ for($i=0; $i<100; $i++) {
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
Notice that we can insert arrays with different key sets into the same
|
||||
|
@ -344,13 +360,14 @@ for($i=0; $i<100; $i++) {
|
|||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.counting">
|
||||
<title>Counting Documents in A Collection</title>
|
||||
<para>
|
||||
Now that we've inserted 101 documents (the 100 we did in the loop, plus the
|
||||
first one), we can check to see if we have them all using the
|
||||
<function>MongoCollection::count</function> method.
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.counting-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -358,12 +375,13 @@ echo $collection->count();
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
</example>
|
||||
and it should print 101.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.cursor">
|
||||
<title>Using a Cursor to Get All of the Documents</title>
|
||||
<para>
|
||||
In order to get all the documents in the collection, we will use
|
||||
|
@ -372,7 +390,8 @@ echo $collection->count();
|
|||
set of documents that matched our query. So to query all of the documents and
|
||||
print them out:
|
||||
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.cursor-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -384,13 +403,14 @@ foreach ($cursor as $id => $value) {
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
and that should print all 101 documents in the collection.
|
||||
<literal>$id</literal> is the <literal>_id</literal> field of a document
|
||||
(cast to a string) and <literal>$value</literal> is the document itself.
|
||||
</para>
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.cursor.seealso">
|
||||
<title>See Also</title>
|
||||
<para>
|
||||
The API documentation on <function>MongoCollection::find</function>
|
||||
|
@ -399,7 +419,7 @@ foreach ($cursor as $id => $value) {
|
|||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.criteria">
|
||||
<title>Setting Criteria for a Query</title>
|
||||
<para>
|
||||
We can create a query to pass to the
|
||||
|
@ -407,7 +427,8 @@ foreach ($cursor as $id => $value) {
|
|||
documents in our collection. For example, if we wanted to find the document
|
||||
for which the value of the "i" field is 71, we would do the following:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.criteria-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -420,11 +441,9 @@ while( $cursor->hasNext() ) {
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
and it should just print just one document:
|
||||
</para>
|
||||
<programlisting>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
array(2) {
|
||||
["_id"]=>
|
||||
|
@ -436,16 +455,18 @@ array(2) {
|
|||
"testCollection"
|
||||
}
|
||||
]]>
|
||||
</programlisting>
|
||||
</screen>
|
||||
</example>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.multi.query">
|
||||
<title>Getting A Set of Documents With a Query</title>
|
||||
<para>
|
||||
We can use the query to get a set of documents from our collection. For
|
||||
example, if we wanted to get all documents where "i" > 50, we could write:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.multi.query-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -458,12 +479,12 @@ while( $cursor->hasNext() ) {
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
which should print the documents where i > 50. We could also get a range, say
|
||||
20 < i <= 30:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
</programlisting>
|
||||
<para>
|
||||
which should print the documents where i > 50. We could also get a range, say
|
||||
20 < i <= 30:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -476,21 +497,23 @@ while( $cursor->hasNext() ) {
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</screen>
|
||||
</example>
|
||||
<para>
|
||||
Remember to always escape the $-symbol or use single quotes. Otherwise PHP
|
||||
will interpret it to be the variable <varname>$gt</varname>.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.tutorial.indexes">
|
||||
<title>Creating An Index</title>
|
||||
<para>
|
||||
MongoDB supports indexes, and they are very easy to add on a collection. To
|
||||
create an index, you specify the field name and direction: ascending (1) or
|
||||
descending (-1). The following creates an ascending index on the "i" field:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<example xml:id="mongo.tutorial.indexes-example">
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
|
@ -499,7 +522,8 @@ $coll->ensureIndex( array( "i" => -1, "j" => 1 ) ); // index on "i" descending,
|
|||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
Indexing is critical for good read performance as your data grows. If you
|
||||
are not familiar with indexing, check out the
|
||||
|
@ -507,5 +531,25 @@ $coll->ensureIndex( array( "i" => -1, "j" => 1 ) ); // index on "i" descending,
|
|||
<link xlink:href="&url.mongodb.dochub.indexes;">MongoDB indexing documentation</link>.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
<!-- 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
|
||||
-->
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section xml:id="mongo.updates" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<chapter xml:id="mongo.updates" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Updates</title>
|
||||
|
||||
<para>
|
||||
|
@ -138,7 +138,7 @@ $blog->update(
|
|||
]]>
|
||||
</programlisting>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section xml:id="mongo.writes" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<chapter xml:id="mongo.writes" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Writes</title>
|
||||
|
||||
<section>
|
||||
|
@ -136,7 +136,7 @@ $blog->update(
|
|||
]]>
|
||||
</programlisting>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
|
|
Loading…
Reference in a new issue