use MongoDB\Builder\Expression;
use MongoDB\Builder\Expression\ResolvesToString;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Stage;
function lcfirst(ResolvesToString|string $expression): ResolvesToString
{
return Expression::concat(
Expression::toLower(
Expression::substr($expression, 0, 1),
),
Expression::substr(
$expression,
Expression::subtract(
Expression::strLenCP(
$expression,
),
1,
),
-1,
),
);
}
$pipeline = new Pipeline(
Stage::project(
lowercaseName: lcfirst(
Expression::stringFieldPath('name'),
)
),
);