Commit c1a8bbc4 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge branch 'v1.3'

parents 6ea28301 8c1c1f1c
...@@ -115,7 +115,7 @@ MongoDB\\Model\\IndexInfo ...@@ -115,7 +115,7 @@ MongoDB\\Model\\IndexInfo
This class implements PHP's :php:`ArrayAccess <arrayaccess>` interface. This This class implements PHP's :php:`ArrayAccess <arrayaccess>` interface. This
provides a mechanism for accessing index fields for which there exists no provides a mechanism for accessing index fields for which there exists no
helper method. :php`isset() <isset>` may be used to check for the existence helper method. :php:`isset() <isset>` may be used to check for the existence
of a field before accessing it with ``[]``. of a field before accessing it with ``[]``.
.. note:: .. note::
......
...@@ -28,6 +28,28 @@ Return Values ...@@ -28,6 +28,28 @@ Return Values
The document limit for the capped collection. If the collection is not capped, The document limit for the capped collection. If the collection is not capped,
``null`` will be returned. ``null`` will be returned.
Examples
--------
.. code-block:: php
<?php
$info = new CollectionInfo([
'name' => 'foo',
'options' => [
'capped' => true,
'size' => 1048576,
'max' => 100,
]
]);
var_dump($info->getCappedMax());
The output would then resemble::
int(100)
See Also See Also
-------- --------
......
...@@ -29,6 +29,27 @@ Return Values ...@@ -29,6 +29,27 @@ Return Values
The size limit for the capped collection in bytes. If the collection is not The size limit for the capped collection in bytes. If the collection is not
capped, ``null`` will be returned. capped, ``null`` will be returned.
Examples
--------
.. code-block:: php
<?php
$info = new CollectionInfo([
'name' => 'foo',
'options' => [
'capped' => true,
'size' => 1048576,
]
]);
var_dump($info->getCappedSize());
The output would then resemble::
int(1048576)
See Also See Also
-------- --------
......
...@@ -26,6 +26,21 @@ Return Values ...@@ -26,6 +26,21 @@ Return Values
The collection name. The collection name.
Examples
--------
.. code-block:: php
<?php
$info = new CollectionInfo(['name' => 'foo']);
echo $info->getName();
The output would then resemble::
foo
See Also See Also
-------- --------
......
...@@ -28,6 +28,32 @@ Return Values ...@@ -28,6 +28,32 @@ Return Values
The collection options. The collection options.
Examples
--------
.. code-block:: php
<?php
$info = new CollectionInfo([
'name' => 'foo',
'options' => [
'capped' => true,
'size' => 1048576,
]
]);
var_dump($info->getOptions());
The output would then resemble::
array(2) {
["capped"]=>
bool(true)
["size"]=>
int(1048576)
}
See Also See Also
-------- --------
......
...@@ -27,6 +27,27 @@ Return Values ...@@ -27,6 +27,27 @@ Return Values
A boolean indicating whether the collection is a capped collection. A boolean indicating whether the collection is a capped collection.
Examples
--------
.. code-block:: php
<?php
$info = new CollectionInfo([
'name' => 'foo',
'options' => [
'capped' => true,
'size' => 1048576,
]
]);
var_dump($info->isCapped());
The output would then resemble::
bool(true)
See Also See Also
-------- --------
......
...@@ -26,6 +26,21 @@ Return Values ...@@ -26,6 +26,21 @@ Return Values
The database name. The database name.
Examples
--------
.. code-block:: php
<?php
$info = new DatabaseInfo(['name' => 'foo']);
echo $info->getName();
The output would then resemble::
foo
See Also See Also
-------- --------
......
...@@ -26,6 +26,21 @@ Return Values ...@@ -26,6 +26,21 @@ Return Values
The total size of the database file on disk in bytes. The total size of the database file on disk in bytes.
Examples
--------
.. code-block:: php
<?php
$info = new DatabaseInfo(['sizeOnDisk' => 1048576]);
var_dump($info->getSizeOnDisk());
The output would then resemble::
int(1048576)
See Also See Also
-------- --------
......
...@@ -26,6 +26,21 @@ Return Values ...@@ -26,6 +26,21 @@ Return Values
A boolean indicating whether the database has any data. A boolean indicating whether the database has any data.
Examples
--------
.. code-block:: php
<?php
$info = new DatabaseInfo(['empty' => true]);
var_dump($info->isEmpty());
The output would then resemble::
bool(true)
See Also See Also
-------- --------
......
...@@ -28,6 +28,26 @@ Return Values ...@@ -28,6 +28,26 @@ Return Values
The index specification as an associative array. The index specification as an associative array.
Examples
--------
.. code-block:: php
<?php
$info = new IndexInfo([
'key' => ['x' => 1],
]);
var_dump($info->getKey());
The output would then resemble::
array(1) {
["x"]=>
int(1)
}
See Also See Also
-------- --------
......
...@@ -29,6 +29,23 @@ Return Values ...@@ -29,6 +29,23 @@ Return Values
The index name. The index name.
Examples
--------
.. code-block:: php
<?php
$info = new IndexInfo([
'name' => 'x_1',
]);
echo $info->getName();
The output would then resemble::
x_1
See Also See Also
-------- --------
......
...@@ -27,6 +27,23 @@ Return Values ...@@ -27,6 +27,23 @@ Return Values
The index namespace. The index namespace.
Examples
--------
.. code-block:: php
<?php
$info = new IndexInfo([
'ns' => 'foo.bar',
]);
echo $info->getNamespace();
The output would then resemble::
foo.bar
See Also See Also
-------- --------
......
...@@ -26,6 +26,23 @@ Return Values ...@@ -26,6 +26,23 @@ Return Values
The index version. The index version.
Examples
--------
.. code-block:: php
<?php
$info = new IndexInfo([
'v' => 1,
]);
var_dump($info->getVersion());
The output would then resemble::
int(1)
See Also See Also
-------- --------
......
...@@ -28,6 +28,23 @@ Return Values ...@@ -28,6 +28,23 @@ Return Values
A boolean indicating whether the index is a sparse index. A boolean indicating whether the index is a sparse index.
Examples
--------
.. code-block:: php
<?php
$info = new IndexInfo([
'sparse' => true,
]);
var_dump($info->isSparse());
The output would then resemble::
bool(true)
See Also See Also
-------- --------
......
...@@ -28,6 +28,23 @@ Return Values ...@@ -28,6 +28,23 @@ Return Values
A boolean indicating whether the index is a TTL index. A boolean indicating whether the index is a TTL index.
Examples
--------
.. code-block:: php
<?php
$info = new IndexInfo([
'expireAfterSeconds' => 100,
]);
var_dump($info->isTtl());
The output would then resemble::
bool(true)
See Also See Also
-------- --------
......
...@@ -28,6 +28,23 @@ Return Values ...@@ -28,6 +28,23 @@ Return Values
A boolean indicating whether the index is a unique index. A boolean indicating whether the index is a unique index.
Examples
--------
.. code-block:: php
<?php
$info = new IndexInfo([
'unique' => true,
]);
var_dump($info->isUnique());
The output would then resemble::
bool(true)
See Also See Also
-------- --------
......
...@@ -851,8 +851,6 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -851,8 +851,6 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertCursorCount(1, $cursor); $this->assertCursorCount(1, $cursor);
} }
public function testExample_55_58() public function testExample_55_58()
{ {
$db = new Database($this->manager, $this->getDatabaseName()); $db = new Database($this->manager, $this->getDatabaseName());
...@@ -1022,6 +1020,166 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1022,6 +1020,166 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertNull($nextChange); $this->assertNull($nextChange);
} }
public function testAggregation_example_1()
{
$db = new Database($this->manager, $this->getDatabaseName());
// Start Aggregation Example 1
$cursor = $db->sales->aggregate([
['$match' => ['items.fruit' => 'banana']],
['$sort' => ['date' => 1]],
]);
// End Aggregation Example 1
$this->assertInstanceOf('MongoDB\Driver\Cursor', $cursor);
}
public function testAggregation_example_2()
{
$db = new Database($this->manager, $this->getDatabaseName());
// Start Aggregation Example 2
$cursor = $db->sales->aggregate([
['$unwind' => '$items'],
['$match' => ['items.fruit' => 'banana']],
[
'$group' => ['_id' => ['day' => ['$dayOfWeek' => '$date']],
'count' => ['$sum' => '$items.quantity']],
],
[
'$project' => [
'dayOfWeek' => '$_id.day',
'numberSold' => '$count',
'_id' => 0,
]
],
['$sort' => ['numberSold' => 1]],
]);
// End Aggregation Example 2
$this->assertInstanceOf('MongoDB\Driver\Cursor', $cursor);
}
public function testAggregation_example_3()
{
$db = new Database($this->manager, $this->getDatabaseName());
// Start Aggregation Example 3
$cursor = $db->sales->aggregate([
['$unwind' => '$items'],
['$group' => [
'_id' => ['day' => ['$dayOfWeek' => '$date']],
'items_sold' => ['$sum' => '$items.quantity'],
'revenue' => [
'$sum' => [
'$multiply' => ['$items.quantity', '$items.price']
]
],
]],
['$project' => [
'day' => '$_id.day',
'revenue' => 1,
'items_sold' => 1,
'discount' => [
'$cond' => [
'if' => ['$lte' => ['$revenue', 250]],
'then' => 25,
'else' => 0,
]
],
]],
]);
// End Aggregation Example 3
$this->assertInstanceOf('MongoDB\Driver\Cursor', $cursor);
}
public function testAggregation_example_4()
{
if (version_compare($this->getServerVersion(), '3.6.0', '<')) {
$this->markTestSkipped('$lookup does not support "let" option');
}
$db = new Database($this->manager, $this->getDatabaseName());
// Start Aggregation Example 4
$cursor = $db->air_alliances->aggregate([
['$lookup' => [
'from' => 'air_airlines',
'let' => ['constituents' => '$airlines'],
'pipeline' => [['$match' => [
'$expr' => ['$in' => ['$name', '$constituents']]
]]],
'as' => 'airlines',
]],
['$project' => [
'_id' => 0,
'name' => 1,
'airlines' => [
'$filter' => [
'input' => '$airlines',
'as' => 'airline',
'cond' => ['$eq' => ['$$airline.country', 'Canada']],
]
],
]],
]);
// End Aggregation Example 4
$this->assertInstanceOf('MongoDB\Driver\Cursor', $cursor);
}
public function testRunCommand_example_1()
{
$db = new Database($this->manager, $this->getDatabaseName());
// Start runCommand Example 1
$cursor = $db->command(['buildInfo' => 1]);
$result = $cursor->toArray()[0];
// End runCommand Example 1
$this->assertInstanceOf('MongoDB\Driver\Cursor', $cursor);
}
public function testRunCommand_example_2()
{
$db = new Database($this->manager, $this->getDatabaseName());
$db->dropCollection('restaurants');
$db->createCollection('restaurants');
// Start runCommand Example 2
$cursor = $db->command(['collStats' => 'restaurants']);
$result = $cursor->toArray()[0];
// End runCommand Example 2
$this->assertInstanceOf('MongoDB\Driver\Cursor', $cursor);
}
public function testIndex_example_1()
{
$db = new Database($this->manager, $this->getDatabaseName());
// Start Index Example 1
$indexName = $db->records->createIndex(['score' => 1]);
// End Index Example 1
$this->assertEquals('score_1', $indexName);
}
public function testIndex_example_2()
{
$db = new Database($this->manager, $this->getDatabaseName());
// Start Index Example 2
$indexName = $db->restaurants->createIndex(
['cuisine' => 1, 'name' => 1],
['partialFilterExpression' => ['rating' => ['$gt' => 5]]]
);
// End Index Example 2
$this->assertEquals('cuisine_1_name_1', $indexName);
}
/** /**
* Return the test collection name. * Return the test collection name.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment