Commit 391334a8 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #320

parents fbbf5bad 5d785088
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
use MongoDB\Collection;
use MongoDB\Driver\ReadPreference;
use MongoDB\Operation\DropCollection;
/**
* CRUD spec functional tests for aggregate().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class AggregateFunctionalTest extends FunctionalTestCase
{
private static $wireVersionForOutOperator = 2;
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testAggregateWithMultipleStages()
{
$cursor = $this->collection->aggregate(
[
['$sort' => ['x' => 1]],
['$match' => ['_id' => ['$gt' => 1]]],
],
['batchSize' => 2]
);
$expected = [
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $cursor);
}
public function testAggregateWithOut()
{
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
if ( ! \MongoDB\server_supports_feature($server, self::$wireVersionForOutOperator)) {
$this->markTestSkipped('$out aggregation pipeline operator is not supported');
}
$outputCollection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName() . '_output');
$operation = new DropCollection($this->getDatabaseName(), $outputCollection->getCollectionName());
$operation->execute($this->getPrimaryServer());
$this->collection->aggregate(
[
['$sort' => ['x' => 1]],
['$match' => ['_id' => ['$gt' => 1]]],
['$out' => $outputCollection->getCollectionName()],
]
);
$expected = [
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $outputCollection->find());
// Manually clean up our output collection
$operation = new DropCollection($this->getDatabaseName(), $outputCollection->getCollectionName());
$operation->execute($this->getPrimaryServer());
}
public function testAggregateWithoutCursorDoesNotApplyTypemap()
{
$pipeline = [
['$group' => [
'_id' => null,
'count' => ['$sum' => 1]
]]
];
$options = ['useCursor' => false];
$result = $this->collection->aggregate($pipeline, $options);
$expected = [
[
'_id' => null,
'count' => 3,
],
];
$this->assertSameDocuments($expected, $result);
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for count().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class CountFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testCountWithoutFilter()
{
$this->assertSame(3, $this->collection->count());
}
public function testCountWithFilter()
{
$filter = ['_id' => ['$gt' => 1]];
$this->assertSame(2, $this->collection->count($filter));
}
public function testCountWithSkipAndLimit()
{
$filter = [];
$options = ['skip' => 1, 'limit' => 3];
$this->assertSame(2, $this->collection->count($filter, $options));
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for deleteMany().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class DeleteManyFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testDeleteManyWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$result = $this->collection->deleteMany($filter);
$this->assertSame(2, $result->getDeletedCount());
$expected = [
['_id' => 1, 'x' => 11],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testDeleteManyWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$result = $this->collection->deleteMany($filter);
$this->assertSame(0, $result->getDeletedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for deleteOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class DeleteOneFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testDeleteOneWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$result = $this->collection->deleteOne($filter);
$this->assertSame(1, $result->getDeletedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testDeleteOneWhenOneDocumentMatches()
{
$filter = ['_id' => 2];
$result = $this->collection->deleteOne($filter);
$this->assertSame(1, $result->getDeletedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testDeleteOneWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$result = $this->collection->deleteOne($filter);
$this->assertSame(0, $result->getDeletedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for distinct().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class DistinctFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testDistinctWithoutFilter()
{
$this->assertSame([11, 22, 33], $this->collection->distinct('x'));
}
public function testDistinctWithFilter()
{
$filter = ['_id' => ['$gt' => 1]];
$this->assertSame([22, 33], $this->collection->distinct('x', $filter));
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for find().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class FindFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(5);
}
public function testFindWithFilter()
{
$filter = ['_id' => 1];
$expected = [
['_id' => 1, 'x' => 11],
];
$this->assertSameDocuments($expected, $this->collection->find($filter));
}
public function testFindWithFilterSortSkipAndLimit()
{
$filter = ['_id' => ['$gt' => 2]];
$options = [
'sort' => ['_id' => 1],
'skip' => 2,
'limit' => 2,
];
$expected = [
['_id' => 5, 'x' => 55],
];
$this->assertSameDocuments($expected, $this->collection->find($filter, $options));
}
public function testFindWithLimitSortAndBatchSize()
{
$filter = [];
$options = [
'sort' => ['_id' => 1],
'limit' => 4,
'batchSize' => 2,
];
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 44],
];
$this->assertSameDocuments($expected, $this->collection->find($filter, $options));
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for findOneAndDelete().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class FindOneAndDeleteFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testFindOneAndDeleteWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndDelete($filter, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndDeleteWhenOneDocumentMatches()
{
$filter = ['_id' => 2];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndDelete($filter, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndDeleteWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndDelete($filter, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
use MongoDB\Operation\FindOneAndReplace;
/**
* CRUD spec functional tests for findOneAndReplace().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => ['$gt' => 1]];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => ['$gt' => 1]];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(['x' => 32], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentBeforeModification()
{
$filter = ['_id' => 2];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentAfterModification()
{
$filter = ['_id' => 2];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(['x' => 32], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => 4];
$replacement = ['x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => 4];
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement = ['_id' => 4, 'x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'upsert' => true,
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 44],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => 4];
$replacement = ['x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => 4];
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement = ['_id' => 4, 'x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
'upsert' => true,
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(['x' => 44], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 44],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
use MongoDB\Operation\FindOneAndUpdate;
/**
* CRUD spec functional tests for findOneAndUpdate().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(['x' => 23], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentBeforeModification()
{
$filter = ['_id' => 2];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentAfterModification()
{
$filter = ['_id' => 2];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(['x' => 23], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'upsert' => true,
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
'upsert' => true,
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(['x' => 1], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
use MongoDB\Driver\BulkWrite;
use MongoDB\Tests\Collection\FunctionalTestCase as BaseFunctionalTestCase;
/**
* Base class for Collection CRUD spec functional tests.
*/
abstract class FunctionalTestCase extends BaseFunctionalTestCase
{
/**
* Create data fixtures.
*
* @param integer $n
*/
protected function createFixtures($n)
{
$bulkWrite = new BulkWrite(['ordered' => true]);
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert([
'_id' => $i,
'x' => (integer) ($i . $i),
]);
}
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
$this->assertEquals($n, $result->getInsertedCount());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for insertMany().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class InsertManyFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(1);
}
public function testInsertManyWithNonexistentDocuments()
{
$documents = [
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$result = $this->collection->insertMany($documents);
$this->assertSame(2, $result->getInsertedCount());
$this->assertSame([2, 3], $result->getInsertedIds());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for insertOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class InsertOneFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(1);
}
public function testInsertOneWithANonexistentDocument()
{
$document = ['_id' => 2, 'x' => 22];
$result = $this->collection->insertOne($document);
$this->assertSame(1, $result->getInsertedCount());
$this->assertSame(2, $result->getInsertedId());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for replaceOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class ReplaceOneFunctionalTest extends FunctionalTestCase
{
private $omitModifiedCount;
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
}
public function testReplaceOneWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$replacement = ['x' => 111];
$result = $this->collection->replaceOne($filter, $replacement);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 111],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWhenOneDocumentMatches()
{
$filter = ['_id' => 1];
$replacement = ['x' => 111];
$result = $this->collection->replaceOne($filter, $replacement);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 111],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$replacement = ['x' => 111];
$result = $this->collection->replaceOne($filter, $replacement);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWithUpsertWhenNoDocumentsMatchWithAnIdSpecified()
{
$filter = ['_id' => 4];
$replacement = ['_id' => 4, 'x' => 1];
$options = ['upsert' => true];
$result = $this->collection->replaceOne($filter, $replacement, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWithUpsertWhenNoDocumentsMatchWithoutAnIdSpecified()
{
$filter = ['_id' => 4];
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement = ['_id' => 4, 'x' => 1];
$options = ['upsert' => true];
$result = $this->collection->replaceOne($filter, $replacement, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for updateMany().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class UpdateManyFunctionalTest extends FunctionalTestCase
{
private $omitModifiedCount;
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
}
public function testUpdateManyWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateMany($filter, $update);
$this->assertSame(2, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(2, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 34],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateManyWhenOneDocumentMatches()
{
$filter = ['_id' => 1];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateMany($filter, $update);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 12],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateManyWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateMany($filter, $update);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateManyWithUpsertWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = ['upsert' => true];
$result = $this->collection->updateMany($filter, $update, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for updateOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class UpdateOneFunctionalTest extends FunctionalTestCase
{
private $omitModifiedCount;
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
}
public function testUpdateOneWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateOne($filter, $update);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateOneWhenOneDocumentMatches()
{
$filter = ['_id' => 1];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateOne($filter, $update);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 12],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateOneWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateOne($filter, $update);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateOneWithUpsertWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = ['upsert' => true];
$result = $this->collection->updateOne($filter, $update, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
This diff is collapsed.
{
"data": [
{
"_id": 1,
"x": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "Aggregate with collation",
"operation": {
"name": "aggregate",
"arguments": {
"pipeline": [
{
"$match": {
"x": "PING"
}
}
],
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": [
{
"_id": 1,
"x": "ping"
}
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "Aggregate with $out",
"operation": {
"name": "aggregate",
"arguments": {
"pipeline": [
{
"$sort": {
"x": 1
}
},
{
"$match": {
"_id": {
"$gt": 1
}
}
},
{
"$out": "other_test_collection"
}
],
"batchSize": 2
}
},
"outcome": {
"result": [
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"collection": {
"name": "other_test_collection",
"data": [
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "Aggregate with multiple stages",
"operation": {
"name": "aggregate",
"arguments": {
"pipeline": [
{
"$sort": {
"x": 1
}
},
{
"$match": {
"_id": {
"$gt": 1
}
}
}
],
"batchSize": 2
}
},
"outcome": {
"result": [
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": "PING"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "Count with collation",
"operation": {
"name": "count",
"arguments": {
"filter": {
"x": "ping"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": 1
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "Count without a filter",
"operation": {
"name": "count",
"arguments": {
"filter": {}
}
},
"outcome": {
"result": 3
}
},
{
"description": "Count with a filter",
"operation": {
"name": "count",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
}
}
},
"outcome": {
"result": 2
}
},
{
"description": "Count with skip and limit",
"operation": {
"name": "count",
"arguments": {
"filter": {},
"skip": 1,
"limit": 3
}
},
"outcome": {
"result": 2
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"string": "PING"
},
{
"_id": 2,
"string": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "Distinct with a collation",
"operation": {
"name": "distinct",
"arguments": {
"fieldName": "string",
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": [
"PING"
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "Distinct without a filter",
"operation": {
"name": "distinct",
"arguments": {
"fieldName": "x",
"filter": {}
}
},
"outcome": {
"result": [
11,
22,
33
]
}
},
{
"description": "Distinct with a filter",
"operation": {
"name": "distinct",
"arguments": {
"fieldName": "x",
"filter": {
"_id": {
"$gt": 1
}
}
}
},
"outcome": {
"result": [
22,
33
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "Find with a collation",
"operation": {
"name": "find",
"arguments": {
"filter": {
"x": "PING"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": [
{
"_id": 1,
"x": "ping"
}
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
},
{
"_id": 5,
"x": 55
}
],
"tests": [
{
"description": "Find with filter",
"operation": {
"name": "find",
"arguments": {
"filter": {
"_id": 1
}
}
},
"outcome": {
"result": [
{
"_id": 1,
"x": 11
}
]
}
},
{
"description": "Find with filter, sort, skip, and limit",
"operation": {
"name": "find",
"arguments": {
"filter": {
"_id": {
"$gt": 2
}
},
"sort": {
"_id": 1
},
"skip": 2,
"limit": 2
}
},
"outcome": {
"result": [
{
"_id": 5,
"x": 55
}
]
}
},
{
"description": "Find with limit, sort, and batchsize",
"operation": {
"name": "find",
"arguments": {
"filter": {},
"sort": {
"_id": 1
},
"limit": 4,
"batchSize": 2
}
},
"outcome": {
"result": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
},
{
"_id": 3,
"x": "pINg"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "DeleteMany when many documents match with collation",
"operation": {
"name": "deleteMany",
"arguments": {
"filter": {
"x": "PING"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"deletedCount": 2
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "DeleteMany when many documents match",
"operation": {
"name": "deleteMany",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
}
}
},
"outcome": {
"result": {
"deletedCount": 2
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
}
]
}
}
},
{
"description": "DeleteMany when no document matches",
"operation": {
"name": "deleteMany",
"arguments": {
"filter": {
"_id": 4
}
}
},
"outcome": {
"result": {
"deletedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
},
{
"_id": 3,
"x": "pINg"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "DeleteOne when many documents matches with collation",
"operation": {
"name": "deleteOne",
"arguments": {
"filter": {
"x": "PING"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"deletedCount": 1
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 3,
"x": "pINg"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "DeleteOne when many documents match",
"operation": {
"name": "deleteOne",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
}
}
},
"outcome": {
"result": {
"deletedCount": 1
}
}
},
{
"description": "DeleteOne when one document matches",
"operation": {
"name": "deleteOne",
"arguments": {
"filter": {
"_id": 2
}
}
},
"outcome": {
"result": {
"deletedCount": 1
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "DeleteOne when no documents match",
"operation": {
"name": "deleteOne",
"arguments": {
"filter": {
"_id": 4
}
}
},
"outcome": {
"result": {
"deletedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
},
{
"_id": 3,
"x": "pINg"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "FindOneAndDelete when one document matches with collation",
"operation": {
"name": "findOneAndDelete",
"arguments": {
"filter": {
"_id": 2,
"x": "PING"
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"x": "ping"
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 3,
"x": "pINg"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "FindOneAndDelete when many documents match",
"operation": {
"name": "findOneAndDelete",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndDelete when one document matches",
"operation": {
"name": "findOneAndDelete",
"arguments": {
"filter": {
"_id": 2
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndDelete when no documents match",
"operation": {
"name": "findOneAndDelete",
"arguments": {
"filter": {
"_id": 4
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "FindOneAndReplace when one document matches with collation returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"x": "PING"
},
"replacement": {
"x": "pong"
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"x": "pong"
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "pong"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "FindOneAndReplace when no documents match without id specified with upsert returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"upsert": true
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match without id specified with upsert returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"x": 44
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match with id specified with upsert returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"upsert": true
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match with id specified with upsert returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"x": 44
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"maxServerVersion": "2.4.99",
"tests": [
{
"description": "FindOneAndReplace when no documents match without id specified with upsert returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"upsert": true
}
},
"outcome": {
"result": null
}
},
{
"description": "FindOneAndReplace when no documents match without id specified with upsert returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"x": 44
}
}
},
{
"description": "FindOneAndReplace when no documents match with id specified with upsert returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"upsert": true
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match with id specified with upsert returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"x": 44
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "FindOneAndReplace when many documents match returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"replacement": {
"x": 32
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 32
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndReplace when many documents match returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"replacement": {
"x": 32
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 32
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 32
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndReplace when one document matches returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 2
},
"replacement": {
"x": 32
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 32
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndReplace when one document matches returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 2
},
"replacement": {
"x": 32
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 32
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 32
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
},
{
"_id": 3,
"x": "pINg"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "FindOneAndUpdate when many documents match with collation returning the document before modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"x": "PING"
},
"update": {
"$set": {
"x": "pong"
}
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"_id": 1
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"x": "ping"
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "pong"
},
{
"_id": 3,
"x": "pINg"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "FindOneAndUpdate when many documents match returning the document before modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when many documents match returning the document after modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 23
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when one document matches returning the document before modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 2
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when one document matches returning the document after modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 2
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 23
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when no documents match returning the document before modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when no documents match with upsert returning the document before modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"upsert": true
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
},
{
"description": "FindOneAndUpdate when no documents match returning the document after modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when no documents match with upsert returning the document after modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"x": 1
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
}
],
"tests": [
{
"description": "InsertMany with non-existing documents",
"operation": {
"name": "insertMany",
"arguments": {
"documents": [
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
},
"outcome": {
"result": {
"insertedIds": [
2,
3
]
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
}
],
"tests": [
{
"description": "InsertOne with a non-existing document",
"operation": {
"name": "insertOne",
"arguments": {
"document": {
"_id": 2,
"x": 22
}
}
},
"outcome": {
"result": {
"insertedId": 2
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "ReplaceOne when one document matches with collation",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"x": "PING"
},
"replacement": {
"_id": 2,
"x": "pong"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "pong"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"maxServerVersion": "2.4.99",
"tests": [
{
"description": "ReplaceOne when many documents match",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"replacement": {
"x": 111
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"upsertedCount": 0
}
}
},
{
"description": "ReplaceOne when one document matches",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 1
},
"replacement": {
"_id": 1,
"x": 111
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 111
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "ReplaceOne when no documents match",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 1
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "ReplaceOne with upsert when no documents match without an id specified",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 1
}
}
},
{
"description": "ReplaceOne with upsert when no documents match with an id specified",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "ReplaceOne with upsert when no documents match without an id specified",
"operation": {
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 1
},
"upsert": true
},
"name": "replaceOne"
},
"outcome": {
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
},
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedId": 4
}
}
},
{
"description": "ReplaceOne with upsert when no documents match with an id specified",
"operation": {
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 1
},
"upsert": true
},
"name": "replaceOne"
},
"outcome": {
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
},
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedId": 4
}
}
}
]
}
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "ReplaceOne when many documents match",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"replacement": {
"x": 111
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
}
}
},
{
"description": "ReplaceOne when one document matches",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 1
},
"replacement": {
"_id": 1,
"x": 111
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 111
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "ReplaceOne when no documents match",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 1
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "ReplaceOne with upsert when no documents match without an id specified",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
},
{
"description": "ReplaceOne with upsert when no documents match with an id specified",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
},
{
"_id": 3,
"x": "pINg"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "UpdateMany when many documents match with collation",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"x": "ping"
},
"update": {
"$set": {
"x": "pong"
}
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"matchedCount": 2,
"modifiedCount": 2,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "pong"
},
{
"_id": 3,
"x": "pong"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"maxServerVersion": "2.4.99",
"tests": [
{
"description": "UpdateMany when many documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 2,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 34
}
]
}
}
},
{
"description": "UpdateMany when one document matches",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 1
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 12
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateMany when no documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateMany with upsert when no documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "UpdateMany when many documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 2,
"modifiedCount": 2,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 34
}
]
}
}
},
{
"description": "UpdateMany when one document matches",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 1
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 12
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateMany when no documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateMany with upsert when no documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "UpdateOne when one document matches with collation",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"x": "PING"
},
"update": {
"$set": {
"x": "pong"
}
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "pong"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"maxServerVersion": "2.4.99",
"tests": [
{
"description": "UpdateOne when many documents match",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"upsertedCount": 0
}
}
},
{
"description": "UpdateOne when one document matches",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": 1
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 12
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateOne when no documents match",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateOne with upsert when no documents match",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
This diff is collapsed.
...@@ -6,6 +6,7 @@ use MongoDB\Driver\Command; ...@@ -6,6 +6,7 @@ use MongoDB\Driver\Command;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use InvalidArgumentException; use InvalidArgumentException;
use stdClass; use stdClass;
......
...@@ -202,7 +202,6 @@ class SpecFunctionalTest extends FunctionalTestCase ...@@ -202,7 +202,6 @@ class SpecFunctionalTest extends FunctionalTestCase
* @param array $assert * @param array $assert
* @param mixed $actualResult * @param mixed $actualResult
* @return mixed * @return mixed
* @throws FileNotFoundException
* @throws LogicException if the operation is unsupported * @throws LogicException if the operation is unsupported
*/ */
private function executeAssert(array $assert, $actualResult) private function executeAssert(array $assert, $actualResult)
...@@ -241,7 +240,6 @@ class SpecFunctionalTest extends FunctionalTestCase ...@@ -241,7 +240,6 @@ class SpecFunctionalTest extends FunctionalTestCase
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $actualResult * @param mixed $actualResult
* @param array $data
* @throws LogicException if the result assertion is unsupported * @throws LogicException if the result assertion is unsupported
*/ */
private function executeAssertResult($expectedResult, $actualResult) private function executeAssertResult($expectedResult, $actualResult)
......
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