diff --git a/generator/config/definitions.php b/generator/config/definitions.php index baf101e..ca3854c 100644 --- a/generator/config/definitions.php +++ b/generator/config/definitions.php @@ -56,16 +56,4 @@ OperatorTestGenerator::class, ], ], - - // Projection Operators - [ - 'configFiles' => __DIR__ . '/projection', - 'namespace' => 'MongoDB\\Builder\\Projection', - 'classNameSuffix' => 'Operator', - 'generators' => [ - OperatorClassGenerator::class, - OperatorFactoryGenerator::class, - OperatorTestGenerator::class, - ], - ], ]; diff --git a/generator/config/expression/slice.yaml b/generator/config/expression/slice.yaml index d0abbbb..22cc287 100644 --- a/generator/config/expression/slice.yaml +++ b/generator/config/expression/slice.yaml @@ -3,7 +3,6 @@ name: $slice link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/' type: - resolvesToArray - - projection encode: array description: | Returns a subset of an array. diff --git a/generator/config/expressions.php b/generator/config/expressions.php index 41cc3ec..76e54fe 100644 --- a/generator/config/expressions.php +++ b/generator/config/expressions.php @@ -89,10 +89,6 @@ 'returnType' => Type\QueryInterface::class, 'acceptedTypes' => [Type\QueryInterface::class, 'array'], ], - 'projection' => [ - 'returnType' => Type\ProjectionInterface::class, - 'acceptedTypes' => [Type\ProjectionInterface::class, ...$bsonTypes['object']], - ], 'accumulator' => [ 'returnType' => Type\AccumulatorInterface::class, 'acceptedTypes' => [Type\AccumulatorInterface::class, ...$bsonTypes['object']], diff --git a/generator/config/projection/elemMatch.yaml b/generator/config/projection/elemMatch.yaml deleted file mode 100644 index 32f6ccd..0000000 --- a/generator/config/projection/elemMatch.yaml +++ /dev/null @@ -1,13 +0,0 @@ -# $schema: ../schema.json -name: $elemMatch -link: 'https://www.mongodb.com/docs/manual/reference/operator/projection/elemMatch/' -type: - - projection -encode: single -description: | - Projects the first element in an array that matches the specified $elemMatch condition. -arguments: - - - name: query - type: - - query diff --git a/generator/config/projection/filter.yaml b/generator/config/projection/filter.yaml deleted file mode 100644 index 50cfaae..0000000 --- a/generator/config/projection/filter.yaml +++ /dev/null @@ -1,34 +0,0 @@ -# $schema: ../schema.json -name: $filter -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/' -type: - - projection -encode: object -description: | - Selects a subset of the array to return an array with only the elements that match the filter condition. -arguments: - - - name: input - type: - - resolvesToArray - - - name: cond - type: - - resolvesToBool - description: | - An expression that resolves to a boolean value used to determine if an element should be included in the output array. The expression references each element of the input array individually with the variable name specified in as. - - - name: as - type: - - string - optional: true - description: | - A name for the variable that represents each individual element of the input array. If no name is specified, the variable name defaults to this. - - - name: limit - type: - - resolvesToInt - optional: true - description: | - A number expression that restricts the number of matching array elements that $filter returns. You cannot specify a limit less than 1. The matching array elements are returned in the order they appear in the input array. - If the specified limit is greater than the number of matching array elements, $filter returns all matching array elements. If the limit is null, $filter returns all matching array elements. diff --git a/generator/config/projection/slice.yaml b/generator/config/projection/slice.yaml deleted file mode 100644 index cfab8f4..0000000 --- a/generator/config/projection/slice.yaml +++ /dev/null @@ -1,17 +0,0 @@ -# $schema: ../schema.json -name: $slice -link: 'https://www.mongodb.com/docs/manual/reference/operator/projection/slice/' -type: - - projection -encode: array -description: | - Limits the number of elements projected from an array. Supports skip and limit slices. -arguments: - - - name: limit - type: - - int - - - name: skip - type: - - int diff --git a/generator/config/query/natural.yaml b/generator/config/query/natural.yaml deleted file mode 100644 index 0d81e90..0000000 --- a/generator/config/query/natural.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# $schema: ../schema.json -name: $natural -link: 'https://www.mongodb.com/docs/manual/reference/operator/meta/natural/' -type: - - projection # @todo: used in sort -encode: object -description: | - A special hint that can be provided via the sort() or hint() methods that can be used to force either a forward or reverse collection scan. diff --git a/generator/config/schema.json b/generator/config/schema.json index 11ccc1e..b48b65a 100644 --- a/generator/config/schema.json +++ b/generator/config/schema.json @@ -23,7 +23,6 @@ "type": "string", "enum": [ "accumulator", - "projection", "stage", "query", "fieldQuery", @@ -113,7 +112,6 @@ "window", "expression", "geometry", - "projection", "fieldPath", "any", "resolvesToNumber", "numberFieldPath", "number", diff --git a/generator/config/stage/project.yaml b/generator/config/stage/project.yaml index ee45a0f..2337940 100644 --- a/generator/config/stage/project.yaml +++ b/generator/config/stage/project.yaml @@ -11,5 +11,4 @@ arguments: name: specification type: - expression - - projection variadic: object diff --git a/src/Builder/Expression/SliceOperator.php b/src/Builder/Expression/SliceOperator.php index 2f4a709..df91721 100644 --- a/src/Builder/Expression/SliceOperator.php +++ b/src/Builder/Expression/SliceOperator.php @@ -12,7 +12,6 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; -use MongoDB\Builder\Type\ProjectionInterface; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Model\BSONArray; @@ -24,7 +23,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/ */ -class SliceOperator implements ResolvesToArray, ProjectionInterface, OperatorInterface +class SliceOperator implements ResolvesToArray, OperatorInterface { public const ENCODE = Encode::Array; diff --git a/src/Builder/Projection/FactoryTrait.php b/src/Builder/Projection/FactoryTrait.php index d3f1d23..359926d 100644 --- a/src/Builder/Projection/FactoryTrait.php +++ b/src/Builder/Projection/FactoryTrait.php @@ -8,13 +8,7 @@ namespace MongoDB\Builder\Projection; -use MongoDB\BSON\PackedArray; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Type\Optional; use MongoDB\Builder\Type\QueryInterface; -use MongoDB\Model\BSONArray; /** * @internal @@ -31,36 +25,4 @@ public static function elemMatch(QueryInterface|array $query): ElemMatchOperator { return new ElemMatchOperator($query); } - - /** - * Selects a subset of the array to return an array with only the elements that match the filter condition. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/ - * @param BSONArray|PackedArray|ResolvesToArray|array $input - * @param ResolvesToBool|bool $cond An expression that resolves to a boolean value used to determine if an element should be included in the output array. The expression references each element of the input array individually with the variable name specified in as. - * @param Optional|string $as A name for the variable that represents each individual element of the input array. If no name is specified, the variable name defaults to this. - * @param Optional|ResolvesToInt|int $limit A number expression that restricts the number of matching array elements that $filter returns. You cannot specify a limit less than 1. The matching array elements are returned in the order they appear in the input array. - * If the specified limit is greater than the number of matching array elements, $filter returns all matching array elements. If the limit is null, $filter returns all matching array elements. - */ - public static function filter( - PackedArray|ResolvesToArray|BSONArray|array $input, - ResolvesToBool|bool $cond, - Optional|string $as = Optional::Undefined, - Optional|ResolvesToInt|int $limit = Optional::Undefined, - ): FilterOperator - { - return new FilterOperator($input, $cond, $as, $limit); - } - - /** - * Limits the number of elements projected from an array. Supports skip and limit slices. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/projection/slice/ - * @param int $limit - * @param int $skip - */ - public static function slice(int $limit, int $skip): SliceOperator - { - return new SliceOperator($limit, $skip); - } } diff --git a/src/Builder/Projection/FilterOperator.php b/src/Builder/Projection/FilterOperator.php deleted file mode 100644 index 3b29e28..0000000 --- a/src/Builder/Projection/FilterOperator.php +++ /dev/null @@ -1,76 +0,0 @@ -input = $input; - $this->cond = $cond; - $this->as = $as; - $this->limit = $limit; - } - - public function getOperator(): string - { - return '$filter'; - } -} diff --git a/src/Builder/Projection/SliceOperator.php b/src/Builder/Projection/SliceOperator.php deleted file mode 100644 index 5f62076..0000000 --- a/src/Builder/Projection/SliceOperator.php +++ /dev/null @@ -1,44 +0,0 @@ -limit = $limit; - $this->skip = $skip; - } - - public function getOperator(): string - { - return '$slice'; - } -} diff --git a/src/Builder/Query/FactoryTrait.php b/src/Builder/Query/FactoryTrait.php index cc480de..fc8cb80 100644 --- a/src/Builder/Query/FactoryTrait.php +++ b/src/Builder/Query/FactoryTrait.php @@ -339,16 +339,6 @@ public static function mod( return new ModOperator($divisor, $remainder); } - /** - * A special hint that can be provided via the sort() or hint() methods that can be used to force either a forward or reverse collection scan. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/meta/natural/ - */ - public static function natural(): NaturalOperator - { - return new NaturalOperator(); - } - /** * Matches all values that are not equal to a specified value. * diff --git a/src/Builder/Query/NaturalOperator.php b/src/Builder/Query/NaturalOperator.php deleted file mode 100644 index 4099209..0000000 --- a/src/Builder/Query/NaturalOperator.php +++ /dev/null @@ -1,32 +0,0 @@ - $specification */ + /** @var stdClass $specification */ public readonly stdClass $specification; /** - * @param Document|ExpressionInterface|ProjectionInterface|Serializable|Type|array|bool|float|int|null|stdClass|string ...$specification + * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string ...$specification */ - public function __construct( - Document|Serializable|Type|ExpressionInterface|ProjectionInterface|stdClass|array|bool|float|int|null|string ...$specification, - ) { + public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|int|null|string ...$specification) + { if (\count($specification) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $specification, got %d.', 1, \count($specification))); } diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index b280785..32ecce7 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -10,7 +10,6 @@ use MongoDB\Builder\BuilderEncoder; use MongoDB\Builder\Expression; use MongoDB\Builder\Pipeline; -use MongoDB\Builder\Projection; use MongoDB\Builder\Query; use MongoDB\Builder\Stage; use MongoDB\Builder\Variable; @@ -157,7 +156,7 @@ public function testExpressionFilter(array $limit, array $expectedLimit): void { $pipeline = new Pipeline( Stage::project( - items: Projection::filter( + items: Expression::filter( ...$limit, input: Expression::arrayFieldPath('items'), cond: Expression::gte(Expression::variable('item.price'), 100), diff --git a/tests/Builder/Projection/Pipelines.php b/tests/Builder/Projection/Pipelines.php deleted file mode 100644 index 251d9e6..0000000 --- a/tests/Builder/Projection/Pipelines.php +++ /dev/null @@ -1,13 +0,0 @@ -