mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-30 07:48:56 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@299506 c90b9560-bf6c-de11-be94-00142212c4b1
129 lines
3.2 KiB
XML
129 lines
3.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<!-- $Revision$ -->
|
|
<refentry xml:id="mongocollection.findone" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>MongoCollection::findOne</refname>
|
|
<refpurpose>Querys this collection, returning a single element</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<modifier>public</modifier> <type>array</type><methodname>MongoCollection::findOne</methodname>
|
|
<methodparam choice="opt"><type>array</type><parameter>query</parameter><initializer>array()</initializer></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>fields</parameter><initializer>array()</initializer></methodparam>
|
|
</methodsynopsis>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term>
|
|
<parameter>query</parameter>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
The fields for which to search.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>
|
|
<parameter>fields</parameter>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
Fields of the results to return.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Returns record matching the search or &null;.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
Throws <classname>MongoConnectionException</classname> if it cannot reach the
|
|
database.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title><methodname>MongoCollection::findOne</methodname> document by its id.</title>
|
|
<para>This example demonstrates how to find a single document in a collection by its id.</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$articles = $mongo->my_db->articles;
|
|
|
|
$article = $articles->findOne(array('_id' => new MongoId('47cc67093475061e3d9536d2')));
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title><methodname>MongoCollection::findOne</methodname> document by some condition.</title>
|
|
<para>This example demonstrates how to find a single document in a collection by some condition and limiting the returned fields.</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$users = $mongo->my_db->users;
|
|
$user = $users->findOne(array('username' => 'jwage'), array('password'));
|
|
print_r($user);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[_id] => MongoId Object
|
|
(
|
|
)
|
|
|
|
[password] => test
|
|
)
|
|
]]>
|
|
</screen>
|
|
<para>
|
|
Notice how even though the document does have a username field, we limited the results
|
|
to only contain the password field.
|
|
</para>
|
|
</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
|
|
-->
|