Commit 0e1516b0 authored by Katherine Walker's avatar Katherine Walker

Merge pull request #478

parents 0d84061d d3ed4b0b
...@@ -16,11 +16,6 @@ description: | ...@@ -16,11 +16,6 @@ description: |
Specifies the initial batch size for the cursor. A batchSize of ``0`` means an Specifies the initial batch size for the cursor. A batchSize of ``0`` means an
empty first batch and is useful for quickly returning a cursor or failure empty first batch and is useful for quickly returning a cursor or failure
message without doing significant server-side work. message without doing significant server-side work.
.. note::
This is not supported for inline aggregation results (i.e. ``useCursor``
option is ``false`` or the server version is < 2.6).
interface: phpmethod interface: phpmethod
operation: ~ operation: ~
optional: true optional: true
...@@ -83,12 +78,6 @@ type: boolean ...@@ -83,12 +78,6 @@ type: boolean
description: | description: |
Indicates whether the command will request that the server provide results Indicates whether the command will request that the server provide results
using a cursor. The default is ``true``. using a cursor. The default is ``true``.
For MongoDB version 2.6 or later, ``useCursor`` allows users to turn off
cursors if necessary to aid in replica set or shard cluster upgrades.
``useCursor`` is ignored for MongoDB versions prior to 2.6 as aggregation
cursors are not available.
interface: phpmethod interface: phpmethod
operation: ~ operation: ~
optional: true optional: true
......
...@@ -69,12 +69,8 @@ arg_name: option ...@@ -69,12 +69,8 @@ arg_name: option
name: 2dsphereIndexVersion name: 2dsphereIndexVersion
type: integer type: integer
description: | description: |
Specifies the :manual:`version of a 2dsphere </core/2dsphere>` index to Overrides the server's default version for a :manual:`2dsphere
create. </core/2dsphere>` index.
MongoDB 2.6 introduced version 2 of 2dsphere indexes. Version 2 is the default
version of 2dsphere indexes created in MongoDB 2.6 and later versions.
``2dsphereIndexVersion`` enables you to override the default version 2.
interface: phpmethod interface: phpmethod
operation: ~ operation: ~
optional: true optional: true
......
...@@ -37,10 +37,6 @@ Return Values ...@@ -37,10 +37,6 @@ Return Values
The total number of documents that were modified by all update and replace The total number of documents that were modified by all update and replace
operations in the bulk write. operations in the bulk write.
The modified count is not available on versions of MongoDB before 2.6, which
used the legacy wire protocol version (i.e. ``OP_UPDATE``). If this is the case,
the modified count will be ``null``.
Errors/Exceptions Errors/Exceptions
----------------- -----------------
......
...@@ -35,10 +35,6 @@ Return Values ...@@ -35,10 +35,6 @@ Return Values
The number of documents that were modified. The number of documents that were modified.
The modified count is not available on versions of MongoDB before 2.6, which
used the legacy wire protocol version (i.e. ``OP_UPDATE``). If this is the case,
the modified count will be ``null``.
Errors/Exceptions Errors/Exceptions
----------------- -----------------
......
...@@ -23,11 +23,6 @@ use MongoDB\Exception\BadMethodCallException; ...@@ -23,11 +23,6 @@ use MongoDB\Exception\BadMethodCallException;
/** /**
* Iterator for applying a type map to documents in inline command results. * Iterator for applying a type map to documents in inline command results.
* *
* This iterator may be used to apply a type map to an array of documents
* returned by a database command (e.g. aggregate on servers < 2.6) and allows
* for functional equivalence with commands that return their results via a
* cursor (e.g. aggregate on servers >= 2.6).
*
* @internal * @internal
*/ */
class TypeMapArrayIterator extends ArrayIterator class TypeMapArrayIterator extends ArrayIterator
......
...@@ -41,7 +41,6 @@ use Traversable; ...@@ -41,7 +41,6 @@ use Traversable;
class Aggregate implements Executable class Aggregate implements Executable
{ {
private static $wireVersionForCollation = 5; private static $wireVersionForCollation = 5;
private static $wireVersionForCursor = 2;
private static $wireVersionForDocumentLevelValidation = 4; private static $wireVersionForDocumentLevelValidation = 4;
private static $wireVersionForReadConcern = 4; private static $wireVersionForReadConcern = 4;
private static $wireVersionForWriteConcern = 5; private static $wireVersionForWriteConcern = 5;
...@@ -100,11 +99,8 @@ class Aggregate implements Executable ...@@ -100,11 +99,8 @@ class Aggregate implements Executable
* * useCursor (boolean): Indicates whether the command will request that * * useCursor (boolean): Indicates whether the command will request that
* the server provide results using a cursor. The default is true. * the server provide results using a cursor. The default is true.
* *
* For servers < 2.6, this option is ignored as aggregation cursors are * This option allows users to turn off cursors if necessary to aid in
* not available. * mongod/mongos upgrades.
*
* For servers >= 2.6, this option allows users to turn off cursors if
* necessary to aid in mongod/mongos upgrades.
* *
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This only * * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This only
* applies when the $out stage is specified. * applies when the $out stage is specified.
...@@ -238,16 +234,15 @@ class Aggregate implements Executable ...@@ -238,16 +234,15 @@ class Aggregate implements Executable
} }
$hasOutStage = \MongoDB\is_last_pipeline_operator_out($this->pipeline); $hasOutStage = \MongoDB\is_last_pipeline_operator_out($this->pipeline);
$isCursorSupported = \MongoDB\server_supports_feature($server, self::$wireVersionForCursor);
$command = $this->createCommand($server, $isCursorSupported); $command = $this->createCommand($server);
$options = $this->createOptions($hasOutStage); $options = $this->createOptions($hasOutStage);
$cursor = $hasOutStage $cursor = $hasOutStage
? $server->executeReadWriteCommand($this->databaseName, $command, $options) ? $server->executeReadWriteCommand($this->databaseName, $command, $options)
: $server->executeReadCommand($this->databaseName, $command, $options); : $server->executeReadCommand($this->databaseName, $command, $options);
if ($isCursorSupported && $this->options['useCursor']) { if ($this->options['useCursor']) {
if (isset($this->options['typeMap'])) { if (isset($this->options['typeMap'])) {
$cursor->setTypeMap($this->options['typeMap']); $cursor->setTypeMap($this->options['typeMap']);
} }
...@@ -272,10 +267,9 @@ class Aggregate implements Executable ...@@ -272,10 +267,9 @@ class Aggregate implements Executable
* Create the aggregate command. * Create the aggregate command.
* *
* @param Server $server * @param Server $server
* @param boolean $isCursorSupported
* @return Command * @return Command
*/ */
private function createCommand(Server $server, $isCursorSupported) private function createCommand(Server $server)
{ {
$cmd = [ $cmd = [
'aggregate' => $this->collectionName, 'aggregate' => $this->collectionName,
...@@ -283,11 +277,6 @@ class Aggregate implements Executable ...@@ -283,11 +277,6 @@ class Aggregate implements Executable
]; ];
$cmdOptions = []; $cmdOptions = [];
// Servers < 2.6 do not support any command options
if ( ! $isCursorSupported) {
return new Command($cmd);
}
$cmd['allowDiskUse'] = $this->options['allowDiskUse']; $cmd['allowDiskUse'] = $this->options['allowDiskUse'];
if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) { if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) {
......
...@@ -19,7 +19,6 @@ namespace MongoDB\Operation; ...@@ -19,7 +19,6 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
...@@ -37,7 +36,6 @@ use MongoDB\Model\IndexInput; ...@@ -37,7 +36,6 @@ use MongoDB\Model\IndexInput;
class CreateIndexes implements Executable class CreateIndexes implements Executable
{ {
private static $wireVersionForCollation = 5; private static $wireVersionForCollation = 5;
private static $wireVersionForCommand = 2;
private static $wireVersionForWriteConcern = 5; private static $wireVersionForWriteConcern = 5;
private $databaseName; private $databaseName;
...@@ -115,9 +113,6 @@ class CreateIndexes implements Executable ...@@ -115,9 +113,6 @@ class CreateIndexes implements Executable
/** /**
* Execute the operation. * Execute the operation.
* *
* For servers < 2.6, this will actually perform an insert operation on the
* database's "system.indexes" collection.
*
* @see Executable::execute() * @see Executable::execute()
* @param Server $server * @param Server $server
* @return string[] The names of the created indexes * @return string[] The names of the created indexes
...@@ -134,11 +129,7 @@ class CreateIndexes implements Executable ...@@ -134,11 +129,7 @@ class CreateIndexes implements Executable
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
if (\MongoDB\server_supports_feature($server, self::$wireVersionForCommand)) { $this->executeCommand($server);
$this->executeCommand($server);
} else {
$this->executeLegacy($server);
}
return array_map(function(IndexInput $index) { return (string) $index; }, $this->indexes); return array_map(function(IndexInput $index) { return (string) $index; }, $this->indexes);
} }
...@@ -180,22 +171,4 @@ class CreateIndexes implements Executable ...@@ -180,22 +171,4 @@ class CreateIndexes implements Executable
$server->executeWriteCommand($this->databaseName, new Command($cmd), $this->createOptions()); $server->executeWriteCommand($this->databaseName, new Command($cmd), $this->createOptions());
} }
/**
* Create one or more indexes for the collection by inserting into the
* "system.indexes" collection (MongoDB <2.6).
*
* @param Server $server
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
private function executeLegacy(Server $server)
{
$bulk = new Bulk(['ordered' => true]);
foreach ($this->indexes as $index) {
$bulk->insert($index);
}
$server->executeBulkWrite($this->databaseName . '.system.indexes', $bulk, new WriteConcern(1));
}
} }
...@@ -712,10 +712,6 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -712,10 +712,6 @@ class DocumentationExamplesTest extends FunctionalTestCase
public function testExample_51_54() public function testExample_51_54()
{ {
if (version_compare($this->getServerVersion(), '2.6.0', '<')) {
$this->markTestSkipped('$currentDate update operator is not supported');
}
$db = new Database($this->manager, $this->getDatabaseName()); $db = new Database($this->manager, $this->getDatabaseName());
// Start Example 51 // Start Example 51
......
...@@ -30,10 +30,6 @@ class AggregateFunctionalTest extends FunctionalTestCase ...@@ -30,10 +30,6 @@ class AggregateFunctionalTest extends FunctionalTestCase
public function testDefaultWriteConcernIsOmitted() public function testDefaultWriteConcernIsOmitted()
{ {
if (version_compare($this->getServerVersion(), '2.6.0', '<')) {
$this->markTestSkipped('$out pipeline operator is not supported');
}
(new CommandObserver)->observe( (new CommandObserver)->observe(
function() { function() {
$operation = new Aggregate( $operation = new Aggregate(
......
...@@ -12,14 +12,12 @@ use MongoDB\Operation\BulkWrite; ...@@ -12,14 +12,12 @@ use MongoDB\Operation\BulkWrite;
class BulkWriteFunctionalTest extends FunctionalTestCase class BulkWriteFunctionalTest extends FunctionalTestCase
{ {
private $collection; private $collection;
private $omitModifiedCount;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName()); $this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
} }
public function testInserts() public function testInserts()
...@@ -70,7 +68,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase ...@@ -70,7 +68,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
$this->assertInstanceOf('MongoDB\BulkWriteResult', $result); $this->assertInstanceOf('MongoDB\BulkWriteResult', $result);
$this->assertSame(5, $result->getMatchedCount()); $this->assertSame(5, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(5, $result->getModifiedCount()); $this->assertSame(5, $result->getModifiedCount());
$this->assertSame(2, $result->getUpsertedCount()); $this->assertSame(2, $result->getUpsertedCount());
$upsertedIds = $result->getUpsertedIds(); $upsertedIds = $result->getUpsertedIds();
...@@ -132,7 +130,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase ...@@ -132,7 +130,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
$this->assertSame([2 => 4], $result->getInsertedIds()); $this->assertSame([2 => 4], $result->getInsertedIds());
$this->assertSame(3, $result->getMatchedCount()); $this->assertSame(3, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(3, $result->getModifiedCount()); $this->assertSame(3, $result->getModifiedCount());
$this->assertSame(1, $result->getUpsertedCount()); $this->assertSame(1, $result->getUpsertedCount());
$this->assertSame([4 => 4], $result->getUpsertedIds()); $this->assertSame([4 => 4], $result->getUpsertedIds());
......
...@@ -31,10 +31,6 @@ class CountFunctionalTest extends FunctionalTestCase ...@@ -31,10 +31,6 @@ class CountFunctionalTest extends FunctionalTestCase
public function testHintOption() public function testHintOption()
{ {
if (version_compare($this->getServerVersion(), '2.6.0', '<')) {
$this->markTestSkipped('count command does not support "hint" option');
}
$insertMany = new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [ $insertMany = new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [
['x' => 1], ['x' => 1],
['x' => 2], ['x' => 2],
......
...@@ -12,8 +12,6 @@ use stdClass; ...@@ -12,8 +12,6 @@ use stdClass;
class CreateIndexesFunctionalTest extends FunctionalTestCase class CreateIndexesFunctionalTest extends FunctionalTestCase
{ {
private static $wireVersionForCommand = 2;
public function testCreateSparseUniqueIndex() public function testCreateSparseUniqueIndex()
{ {
$indexes = [['key' => ['x' => 1], 'sparse' => true, 'unique' => true]]; $indexes = [['key' => ['x' => 1], 'sparse' => true, 'unique' => true]];
...@@ -120,25 +118,6 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase ...@@ -120,25 +118,6 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase
*/ */
public function testCreateConflictingIndexesWithCommand() public function testCreateConflictingIndexesWithCommand()
{ {
if ( ! \MongoDB\server_supports_feature($this->getPrimaryServer(), self::$wireVersionForCommand)) {
$this->markTestSkipped('createIndexes command is not supported');
}
$indexes = [
['key' => ['x' => 1], 'sparse' => true, 'unique' => false],
['key' => ['x' => 1], 'sparse' => false, 'unique' => true],
];
$operation = new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), $indexes);
$createdIndexNames = $operation->execute($this->getPrimaryServer());
}
public function testCreateConflictingIndexesWithLegacyInsert()
{
if (\MongoDB\server_supports_feature($this->getPrimaryServer(), self::$wireVersionForCommand)) {
$this->markTestSkipped('Index creation does not use legacy insertion');
}
$indexes = [ $indexes = [
['key' => ['x' => 1], 'sparse' => true, 'unique' => false], ['key' => ['x' => 1], 'sparse' => true, 'unique' => false],
['key' => ['x' => 1], 'sparse' => false, 'unique' => true], ['key' => ['x' => 1], 'sparse' => false, 'unique' => true],
...@@ -146,28 +125,10 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase ...@@ -146,28 +125,10 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase
$operation = new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), $indexes); $operation = new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), $indexes);
$createdIndexNames = $operation->execute($this->getPrimaryServer()); $createdIndexNames = $operation->execute($this->getPrimaryServer());
/* When creating indexes with legacy insert operations, the server
* ignores conflicting index specifications and leaves the original
* index in place.
*/
$this->assertSame('x_1', $createdIndexNames[0]);
$this->assertIndexExists('x_1', function(IndexInfo $info) {
$this->assertTrue($info->isSparse());
$this->assertFalse($info->isUnique());
$this->assertFalse($info->isTtl());
});
} }
public function testDefaultWriteConcernIsOmitted() public function testDefaultWriteConcernIsOmitted()
{ {
/* Earlier server versions do not support the createIndexes command. Per
* the Index Management specification, inserts on system.indexes must
* use the write concern {w:1}. */
if ( ! \MongoDB\server_supports_feature($this->getPrimaryServer(), self::$wireVersionForCommand)) {
$this->markTestSkipped('createIndexes command is not supported');
}
(new CommandObserver)->observe( (new CommandObserver)->observe(
function() { function() {
$operation = new CreateIndexes( $operation = new CreateIndexes(
......
...@@ -11,14 +11,12 @@ use MongoDB\Operation\Update; ...@@ -11,14 +11,12 @@ use MongoDB\Operation\Update;
class UpdateFunctionalTest extends FunctionalTestCase class UpdateFunctionalTest extends FunctionalTestCase
{ {
private $collection; private $collection;
private $omitModifiedCount;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName()); $this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
} }
public function testUpdateOne() public function testUpdateOne()
...@@ -33,7 +31,7 @@ class UpdateFunctionalTest extends FunctionalTestCase ...@@ -33,7 +31,7 @@ class UpdateFunctionalTest extends FunctionalTestCase
$this->assertInstanceOf('MongoDB\UpdateResult', $result); $this->assertInstanceOf('MongoDB\UpdateResult', $result);
$this->assertSame(1, $result->getMatchedCount()); $this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount()); $this->assertSame(1, $result->getModifiedCount());
$this->assertSame(0, $result->getUpsertedCount()); $this->assertSame(0, $result->getUpsertedCount());
$this->assertNull($result->getUpsertedId()); $this->assertNull($result->getUpsertedId());
...@@ -59,7 +57,7 @@ class UpdateFunctionalTest extends FunctionalTestCase ...@@ -59,7 +57,7 @@ class UpdateFunctionalTest extends FunctionalTestCase
$this->assertInstanceOf('MongoDB\UpdateResult', $result); $this->assertInstanceOf('MongoDB\UpdateResult', $result);
$this->assertSame(2, $result->getMatchedCount()); $this->assertSame(2, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(2, $result->getModifiedCount()); $this->assertSame(2, $result->getModifiedCount());
$this->assertSame(0, $result->getUpsertedCount()); $this->assertSame(0, $result->getUpsertedCount());
$this->assertNull($result->getUpsertedId()); $this->assertNull($result->getUpsertedId());
...@@ -85,7 +83,7 @@ class UpdateFunctionalTest extends FunctionalTestCase ...@@ -85,7 +83,7 @@ class UpdateFunctionalTest extends FunctionalTestCase
$this->assertInstanceOf('MongoDB\UpdateResult', $result); $this->assertInstanceOf('MongoDB\UpdateResult', $result);
$this->assertSame(0, $result->getMatchedCount()); $this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount()); $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(1, $result->getUpsertedCount()); $this->assertSame(1, $result->getUpsertedCount());
$this->assertSame(5, $result->getUpsertedId()); $this->assertSame(5, $result->getUpsertedId());
...@@ -112,7 +110,7 @@ class UpdateFunctionalTest extends FunctionalTestCase ...@@ -112,7 +110,7 @@ class UpdateFunctionalTest extends FunctionalTestCase
$this->assertInstanceOf('MongoDB\UpdateResult', $result); $this->assertInstanceOf('MongoDB\UpdateResult', $result);
$this->assertSame(0, $result->getMatchedCount()); $this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount()); $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(1, $result->getUpsertedCount()); $this->assertSame(1, $result->getUpsertedCount());
$this->assertInstanceOf('MongoDB\BSON\ObjectId', $result->getUpsertedId()); $this->assertInstanceOf('MongoDB\BSON\ObjectId', $result->getUpsertedId());
......
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