Uploaded image for project: 'PHP Driver: Library'
  1. PHP Driver: Library
  2. PHPLIB-1371

Add examples on using the aggregation builder

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Builder, Docs Examples
    • None

      How to use the aggregation builder to perform an actual aggregation

      // code placeholder
      

      How to create custom operator factories

      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'),
              )
          ),
      ); 

            Assignee:
            Unassigned Unassigned
            Reporter:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: