Skip to content

Commit

Permalink
Fix wrong syntax for replaceRoot stage
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Jul 9, 2019
1 parent a50624c commit ed02702
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Stage/ReplaceRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function __construct(Builder $builder, DocumentManager $documentManager,
public function getExpression() : array
{
return [
'$replaceRoot' => $this->expression !== null ? $this->convertExpression($this->expression) : $this->expr->getExpression(),
'$replaceRoot' => [
'newRoot' => $this->expression !== null ? $this->convertExpression($this->expression) : $this->expr->getExpression(),
],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public function testTypeConversion()
$this->assertEquals(
[
'$replaceRoot' => [
'isToday' => ['$eq' => ['$createdAt', $mongoDate]],
'newRoot' => [
'isToday' => ['$eq' => ['$createdAt', $mongoDate]],
],
],
],
$stage->getExpression()
Expand All @@ -49,7 +51,9 @@ public function testTypeConversionWithDirectExpression()
$this->assertEquals(
[
'$replaceRoot' => [
'isToday' => ['$eq' => ['$createdAt', $mongoDate]],
'newRoot' => [
'isToday' => ['$eq' => ['$createdAt', $mongoDate]],
],
],
],
$stage->getExpression()
Expand All @@ -68,7 +72,9 @@ public function testFieldNameConversion()
$this->assertEquals(
[
'$replaceRoot' => [
'someField' => ['$concat' => ['$ip', 'foo']],
'newRoot' => [
'someField' => ['$concat' => ['$ip', 'foo']],
],
],
],
$stage->getExpression()
Expand All @@ -83,7 +89,9 @@ public function testFieldNameConversionWithDirectExpression()
->replaceRoot('$authorIp');

$this->assertEquals(
['$replaceRoot' => '$ip'],
[
'$replaceRoot' => ['newRoot' => '$ip']
],
$stage->getExpression()
);
}
Expand Down

0 comments on commit ed02702

Please sign in to comment.