Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-1128

Aggregation pipelines are broken on sharded collections

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.4.2
    • Affects Version/s: 1.4.0, 1.4.1
    • Component/s: None
    • None
    • Environment:
      PHP 7.2.2-3+ubuntu14.04.1+deb.sury.org+1 on both CLI and PHP-FPM

      MongoDB extension version => 1.4.1
      libbson bundled version => 1.9.2
      libmongoc bundled version => 1.9.2

      PHP library: mongodb/mongodb: 1.2.0

      When we try to run an aggregation pipeline on a sharded collection we get the following exception:

      MongoDB\Driver\Exception\RuntimeException: Cannot use $-modifiers in opts: "$gleStats"
      

      On a non-sharded collection this works fine. Also the same aggregation on the same collection without any code change was working with version 1.3.4.

      Code to reproduce:

      
      $accountId = 600;
      $offset = 0;
      $limit = 10;
      
      $aggregateQuery = [
          ['$match' => ['_id' => $accountId,]],
          ['$unwind' => '$items'],
          ['$sort' => ['items.d' => -1]],
          [
              '$group' => [
                  '_id' => '_id',
                  'total' => ['$sum' => 1],
                  'results' => ['$push' => '$$ROOT']
              ]
          ],
          [
              '$project' => [
                  'total' => 1,
                  'items' => [
                      '$slice' => [
                          '$results.items',
                          $offset,
                          $limit
                      ]
                  ]
              ]
          ],
      ];
      
      
      $aggregated = $client->selectCollection('profiles', 'sortableResearchItems')->aggregate($aggregateQuery);
      $items = [];
      $total = null;
      foreach ($aggregated as $doc) {
          if (isset($doc['total']) && isset($doc['items'])) {
              $total = $doc['total'];
              foreach ($doc['items'] as $item) {
                  var_dump($item);
              }
          }
      }
      

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            bashofmann Bastian Hofmann
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: