php-doc-en/reference/mongo/mongocollection/count.xml

197 lines
5.5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongocollection.count" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoCollection::count</refname>
<refpurpose>Counts the number of documents in this collection</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>int</type><methodname>MongoCollection::count</methodname>
<methodparam choice="opt"><type>array</type><parameter>query</parameter><initializer>array()</initializer></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term>
<parameter>query</parameter>
</term>
<listitem>
<para>
Associative array or object with fields to match.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>options</parameter>
</term>
<listitem>
<para>
An array of options for the index creation. Currently available options
include:
<informaltable>
<tgroup cols="3">
<thead>
<row>
<entry>&Name;</entry>
<entry>&Type;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry><varname>hint</varname></entry>
<entry><type>mixed</type></entry>
<entry>
<para>
Index to use for the query. If a string is passed, it should
correspond to an index name. If an array or object is passed, it
should correspond to the specification used to create the index
(i.e. the first argument to
<function>MongoCollection::createIndex</function>).
</para>
<simpara>This option is only supported in MongoDB 2.6+.</simpara>
</entry>
</row>
<row>
<entry><varname>limit</varname></entry>
<entry><type>integer</type></entry>
<entry>The maximum number of matching documents to return.</entry>
</row>
<row>
<entry><varname>maxTimeMS</varname></entry>
<entry><type>integer</type></entry>
<entry>
<para>
Specifies a cumulative time limit in milliseconds for processing
the operation (does not include idle time). If the operation is not
completed within the timeout period, a
<classname>MongoExecutionTimeoutException</classname> will be
thrown.
</para>
<simpara>This option is only supported in MongoDB 2.6+.</simpara>
</entry>
</row>
<row>
<entry><varname>skip</varname></entry>
<entry><type>integer</type></entry>
<entry>The number of matching documents to skip before returning results.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the number of documents matching the query.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoResultException</classname> if the server could not
execute the command due to an error.
</para>
<para>
Throws <classname>MongoExecutionTimeoutException</classname> if command
execution was terminated due to <varname>maxTimeMS</varname>.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>1.6.0</entry>
<entry>
The second parameter is now an <parameter>options</parameter> array.
Passing <parameter>limit</parameter> and <parameter>skip</parameter> as
the second and third parameters, respectively, is deprecated.
</entry>
</row>
<row>
<entry>1.0.7</entry>
<entry>
Added <parameter>limit</parameter> and <parameter>skip</parameter> as
second and third parameters, respectively.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoCollection::count</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$collection->insert(array('x'=>1));
$collection->insert(array('x'=>2));
$collection->insert(array('x'=>3));
var_dump($collection->count());
var_dump($collection->count(array('x'=>1)));
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
int(3)
int(1)
]]>
</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
-->