Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5264e26
+ implement $expr operator as exprOp method for query and aggregation…
Jul 17, 2021
4725c19
* fix MatchStage expr revision introduced bug
Jul 17, 2021
0a38fa5
+ add exprOp test
Jul 18, 2021
c319eca
+ fix exprOp test
Jul 18, 2021
7ba6315
+ fix exprOp test
Jul 18, 2021
61aafa3
Merge remote-tracking branch 'origin/2.3.x' into support-expr-in-queries
Jan 31, 2022
06a95f1
+ update methods name refactoring as suggested in PR #2343 (exprOr to…
Jan 31, 2022
3de0efb
Merge branch '2.3.x' into support-expr-in-queries
Jan 31, 2022
fe79bbd
+ used phpcbf on /lib
Mar 8, 2022
898ce49
+ used phpcbf on /tests
Mar 8, 2022
5b6a368
+ implement $expr operator as exprOp method for query and aggregation…
Jul 17, 2021
e865bd0
* fix MatchStage expr revision introduced bug
Jul 17, 2021
4285401
+ add exprOp test
Jul 18, 2021
eece492
+ fix exprOp test
Jul 18, 2021
8e4ea1b
+ fix exprOp test
Jul 18, 2021
ccaa1a4
+ update methods name refactoring as suggested in PR #2343 (exprOr to…
Jan 31, 2022
110375e
+ rebase on newer 2.3.x
Mar 8, 2022
caf12dd
Merge remote-tracking branch 'fork/support-expr-in-queries' into supp…
Mar 8, 2022
d1660cd
- remove test on previously removed method (aggregationExpression)
Mar 8, 2022
0b458de
+ implement $expr operator as exprOp method for query and aggregation…
Jul 17, 2021
839adc2
* fix MatchStage expr revision introduced bug
Jul 17, 2021
fb14785
+ add exprOp test
Jul 18, 2021
906d5bc
+ fix exprOp test
Jul 18, 2021
67e6913
+ fix exprOp test
Jul 18, 2021
b387bff
+ update methods name refactoring as suggested in PR #2343 (exprOr to…
Jan 31, 2022
372a27b
+ rebase on newer 2.3.x
Mar 8, 2022
9d5845c
+ used phpcbf on /tests
Mar 8, 2022
c30899b
- remove test on previously removed method (aggregationExpression)
Mar 8, 2022
a3dfb0d
+ minor documentation updates
vincent-le-henaff Nov 4, 2022
a9b8dd6
Merge remote-tracking branch 'origin/support-expr-in-queries' into su…
vincent-le-henaff Nov 4, 2022
9746da5
+ applied vendor/bin/phpcbf
vincent-le-henaff Nov 4, 2022
a28c84c
+ minors fixes for vendor/bin/phpstan validation
vincent-le-henaff Nov 4, 2022
771b43d
+ rollback some unexpected changes in previous commits
vincent-le-henaff Nov 5, 2022
eb60a6f
+ replaced Query\Builder::expr() calls to Query\Builder::createQueryE…
vincent-le-henaff Nov 6, 2022
b5b2a82
+ adding regexMatch to Aggretation
vincent-le-henaff Nov 11, 2022
055669b
+ adding regexMatch to Aggretation
vincent-le-henaff Jul 6, 2025
68a85e2
+ update mongo extension requirements
vincent-le-henaff Jul 6, 2025
324c661
Merge remote-tracking branch 'origin/support-expr-in-queries' into su…
vincent-le-henaff Jul 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ public function count(string $fieldName): Stage\Count
return $stage;
}

/**
* Create a new Expr instance that can be used as an expression with the Builder
*/
public function createExpr(): Expr
{
return new Expr($this->dm, $this->class);
}

/**
* Executes the aggregation pipeline
*
Expand All @@ -180,9 +188,12 @@ public function execute(array $options = []): Iterator
return $this->getAggregation($options)->getIterator();
}

/**
* @deprecated use createExpr instead
*/
public function expr(): Expr
{
return new Expr($this->dm, $this->class);
return $this->createExpr();
}

/**
Expand Down
25 changes: 24 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ public static function convertExpression($expression)
return $expression;
}

/**
* Returns a new expression object
*/
public function createExpr(): self
{
return new static($this->dm, $this->class);
}

/**
* Converts a date object to a string according to a user-specified format.
*
Expand Down Expand Up @@ -462,10 +470,25 @@ public function exp($exponent): self

/**
* Returns a new expression object
*
* @deprecated use createExpr instead
*/
public function expr(): self
{
return new static($this->dm, $this->class);
return $this->createExpr();
}

/**
* Specify $expr criteria for the current field.
*
* @see Builder::expr()
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
*
* @param array|self $expression
*/
public function exprOp($expression): self
{
return $this->operator('$expr', $expression);
}

/**
Expand Down
29 changes: 26 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/MatchStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ public function all(array $values): self
return $this;
}

/**
* Create a new Expr instance that can be used to build partial expressions
* for other operator methods.
*/
public function createExpr(): Expr
{
return $this->builder->matchExpr();
}

/**
* Specify $elemMatch criteria for the current field.
*
Expand Down Expand Up @@ -153,12 +162,26 @@ public function exists(bool $bool): self
}

/**
* Create a new Expr instance that can be used to build partial expressions
* for other operator methods.
* @deprecated use createExpr instead
*/
public function expr(): Expr
{
return $this->builder->matchExpr();
return $this->createExpr();
}

/**
* Specify $expr criteria for the current field.
*
* @see Expr::exprOp()
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
*
* @param array|\Doctrine\ODM\MongoDB\Aggregation\Expr $expression
*/
public function exprOp($expression): self
{
$this->query->exprOp($expression);

return $this;
}

/**
Expand Down
31 changes: 28 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,17 @@ public function count(): self
return $this;
}

/**
* Create a new Expr instance that can be used as an expression with the Builder
*/
public function createExpr(): Expr
{
$expr = new Expr($this->dm);
$expr->setClassMetadata($this->class);

return $expr;
}

/**
* Sets the value of the current field to the current date, either as a date or a timestamp.
*
Expand Down Expand Up @@ -493,13 +504,27 @@ public function exists(bool $bool): self

/**
* Create a new Expr instance that can be used as an expression with the Builder
*
* @deprecated use createExpr instead
*/
public function expr(): Expr
{
$expr = new Expr($this->dm);
$expr->setClassMetadata($this->class);
return $this->createExpr();
}

return $expr;
/**
* Specify $expr criteria for the current field.
*
* @see Expr::exprOp()
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
*
* @param array|Expr $expression
*/
public function exprOp($expression): self
{
$this->expr->exprOp($expression);

return $this;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Query/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,19 @@ public function elemMatch($expression): self
return $this->operator('$elemMatch', $expression);
}

/**
* Specify $expr criteria for the current field.
*
* @see Builder::exprOp()
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
*
* @param array|Expr $expression
*/
public function exprOp($expression): self
{
return $this->operator('$expr', $expression);
}

/**
* Specify an equality match for the current field.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ public static function provideExpressionOperators()
'operator' => 'exp',
'args' => ['$field'],
],
'exprOp' => [
'expected' => ['$expr' => ['$eq' => ['$field', '$otherField']]],
'operator' => 'exprOp',
'args' => [['$eq' => ['$field', '$otherField']]],
],
'filter' => [
'expected' => ['$filter' => ['input' => '$array', 'as' => '$as', 'cond' => '$cond']],
'operator' => 'filter',
Expand Down