Skip to content

Commit

Permalink
Lift sharding restrictions from $lookup and $graphLookup
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Dec 20, 2022
1 parent 632ad8e commit 7a6fcd9
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 51 deletions.
10 changes: 0 additions & 10 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ public function depthField(string $depthField): self
* Target collection for the $graphLookup operation to search, recursively
* matching the connectFromField to the connectToField.
*
* The from collection cannot be sharded and must be in the same database as
* any other collections used in the operation.
*
* @psalm-param class-string|string $from
*/
public function from(string $from): self
Expand All @@ -161,10 +158,6 @@ public function from(string $from): self
return $this;
}

if ($this->targetClass->isSharded()) {
throw MappingException::cannotUseShardedCollectionInLookupStages($this->targetClass->name);
}

$this->from = $this->targetClass->getCollection();

return $this;
Expand Down Expand Up @@ -239,9 +232,6 @@ private function fromReference(string $fieldName): self

$referenceMapping = $this->class->getFieldMapping($fieldName);
$this->targetClass = $this->dm->getClassMetadata($referenceMapping['targetDocument']);
if ($this->targetClass->isSharded()) {
throw MappingException::cannotUseShardedCollectionInLookupStages($this->targetClass->name);
}

$this->from = $this->targetClass->getCollection();

Expand Down
9 changes: 0 additions & 9 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public function alias(string $alias): self

/**
* Specifies the collection or field name in the same database to perform the join with.
*
* Starting in MongoDB 5.1, the from collection can be sharded.
*/
public function from(string $from): self
{
Expand All @@ -88,10 +86,6 @@ public function from(string $from): self
return $this;
}

if ($this->targetClass->isSharded()) {
throw MappingException::cannotUseShardedCollectionInLookupStages($this->targetClass->name);
}

$this->from = $this->targetClass->getCollection();

return $this;
Expand Down Expand Up @@ -214,9 +208,6 @@ private function fromReference(string $fieldName): self

$referenceMapping = $this->class->getFieldMapping($fieldName);
$this->targetClass = $this->dm->getClassMetadata($referenceMapping['targetDocument']);
if ($this->targetClass->isSharded()) {
throw MappingException::cannotUseShardedCollectionInLookupStages($this->targetClass->name);
}

$this->from = $this->targetClass->getCollection();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Documents\GraphLookup\Employee;
use Documents\GraphLookup\ReportingHierarchy;
use Documents\GraphLookup\Traveller;
use Documents\Sharded\ShardedOne;
use Documents\User;

use function array_merge;
Expand Down Expand Up @@ -252,15 +251,6 @@ public function testGraphLookupWithTraveller(Closure $addGraphLookupStage, array
self::assertCount(3, $result);
}

public function testGraphLookupToShardedCollectionThrowsException(): void
{
$builder = $this->dm->createAggregationBuilder(User::class);

$this->expectException(MappingException::class);
$builder
->graphLookup(ShardedOne::class);
}

public function testGraphLookupWithUnmappedFields(): void
{
$builder = $this->dm->createAggregationBuilder(User::class);
Expand Down
22 changes: 0 additions & 22 deletions tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/LookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace Doctrine\ODM\MongoDB\Tests\Aggregation\Stage;

use Doctrine\ODM\MongoDB\Mapping\MappingException;
use Doctrine\ODM\MongoDB\Tests\BaseTest;
use Documents\CmsComment;
use Documents\ReferenceUser;
use Documents\Sharded\ShardedOne;
use Documents\SimpleReferenceUser;
use Documents\User;

Expand Down Expand Up @@ -406,26 +404,6 @@ public function testLookupStageReferenceManyInverseStoreAsRef(): void
self::assertCount(1, $result[0]['embeddedReferenceManyInverse']);
}

public function testLookupToShardedCollectionThrowsException(): void
{
$builder = $this->dm->createAggregationBuilder(User::class);

$this->expectException(MappingException::class);
$builder
->lookup(ShardedOne::class)
->localField('id')
->foreignField('id');
}

public function testLookupToShardedReferenceThrowsException(): void
{
$builder = $this->dm->createAggregationBuilder(ShardedOne::class);

$this->expectException(MappingException::class);
$builder
->lookup('user');
}

private function insertTestData(): void
{
$user1 = new User();
Expand Down

0 comments on commit 7a6fcd9

Please sign in to comment.