<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Returns information about collections in this database</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongodb.get.html">MongoDB::__get</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongodb.getcollectionnames.html">MongoDB::getCollectionNames</a></div> <div class="up"><a href="class.mongodb.html">MongoDB</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongodb.getcollectioninfo" class="refentry"> <div class="refnamediv"> <h1 class="refname">MongoDB::getCollectionInfo</h1> <p class="verinfo">(PECL mongo >=1.6.0)</p><p class="refpurpose"><span class="refname">MongoDB::getCollectionInfo</span> — <span class="dc-title">Returns information about collections in this database</span></p> </div> <div class="refsect1 description" id="refsect1-mongodb.getcollectioninfo-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">array</span> <span class="methodname"><strong>MongoDB::getCollectionInfo</strong></span> ([ <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code><span class="initializer"> = array()</span></span> ] )</div> <p class="para rdfs-comment"> Gets a list of all collections in the database and returns them as an array of documents, which contain their names and options. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">This method will use the <a href="https://docs.mongodb.com/manual/reference/command/listCollections" class="link external">» listCollections</a> database command when communicating with MongoDB 2.8+. For previous database versions, the method will query the special <em>system.namespaces</em> collection.</span></p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-mongodb.getcollectioninfo-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">options</code> </dt> <dd> <p class="para"> An array of options for listing the collections. Currently available options include: <ul class="itemizedlist"> <li class="listitem"><p class="para"><em>"filter"</em></p><p class="para">Optional query criteria. If provided, this criteria will be used to filter the collections included in the result.</p><p class="para">Relevant fields that may be queried include <em>"name"</em> (collection name as a string, without the database name prefix) and <em>"options" (object containing options used to create the collection).</em>.</p><blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">MongoDB 2.6 and earlier versions require the <em>"name"</em> criteria, if specified, to be a string value (i.e. equality match). This is because the driver must prefix the value with the database name in order to query the <em>system.namespaces</em> collection. Later versions of MongoDB do not have this limitation, as the driver will use the listCollections command.</span></p></blockquote></li> <li class="listitem"><p class="para"><em>"includeSystemCollections"</em></p><p class="para">Boolean, defaults to <strong><code>FALSE</code></strong>. Determines whether system collections should be included in the result.</p></li> </ul> </p> <p class="para"> The following option may be used with MongoDB 2.8+: <ul class="itemizedlist"> <li class="listitem"><p class="para"><em>"maxTimeMS"</em></p><p class="para">Specifies a cumulative time limit in milliseconds for processing the operation on the server (does not include idle time). If the operation is not completed by the server within the timeout period, a <a href="class.mongoexecutiontimeoutexception.html" class="classname">MongoExecutionTimeoutException</a> will be thrown.</p></li> </ul> </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-mongodb.getcollectioninfo-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> This function returns an array where each element is an array describing a collection. Elements will contain a <em>name</em> key denoting the name of the collection, and optionally contain an <em>options</em> key denoting an array of objects used to create the collection. For example, capped collections will include <em>capped</em> and <em>size</em> options. </p> </div> <div class="refsect1 errors" id="refsect1-mongodb.getcollectioninfo-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> For MongoDB 2.6 and earlier, <a href="class.mongoexception.html" class="classname">MongoException</a> will be thrown if a non-string value was specified for the <em>"filter"</em> option's <em>"name"</em> criteria. </p> </div> <div class="refsect1 examples" id="refsect1-mongodb.getcollectioninfo-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-1551"> <p><strong>Example #1 <span class="function"><strong>MongoDB::getCollectionInfo()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$m </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$db </span><span style="color: #007700">= </span><span style="color: #0000BB">$m</span><span style="color: #007700">-></span><span style="color: #0000BB">selectDB</span><span style="color: #007700">(</span><span style="color: #DD0000">"demo"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">getCollectionInfo</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> array(2) { [0]=> array(2) { ["name"]=> string(4) "logs" ["options"]=> array(2) { ["capped"]=> bool(true) ["size"]=> int(10240) } } [1]=> array(2) { ["name"]=> string(5) "users" ["options"]=> array(1) { ["flags"]=> int(1) } } } </pre></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-mongodb.getcollectioninfo-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="function"><a href="mongodb.getcollectionnames.html" class="function" rel="rdfs-seeAlso">MongoDB::getCollectionNames()</a> - Gets an array of names for all collections in this database</span></li> <li class="member"><span class="function"><a href="mongodb.listcollections.html" class="function" rel="rdfs-seeAlso">MongoDB::listCollections()</a> - Gets an array of MongoCollection objects for all collections in this database</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongodb.get.html">MongoDB::__get</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongodb.getcollectionnames.html">MongoDB::getCollectionNames</a></div> <div class="up"><a href="class.mongodb.html">MongoDB</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>