Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1868

Running aggregate against a database with a single stage fails

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.3.3
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      OS:
      node.js / npm versions:
      Additional info:
    • Developer Tools
    • 2
    • Needed
    • Hide

      The aggregate function will now have the same API as the aggregate function for a collection i.e. `db.{collection}.aggregate` so

      db.aggregate({ $stage: 1 }, { $stage2: true }) 
      // equivalent to db.aggregate([{ $stage: 1 }, { $stage2: true })]); 

      See also: https://github.com/mongodb-js/mongosh/pull/2229

      Show
      The aggregate function will now have the same API as the aggregate function for a collection i.e. `db.{collection}.aggregate` so db.aggregate({ $stage: 1 }, { $stage2: true }) // equivalent to db.aggregate([{ $stage: 1 }, { $stage2: true })]); See also: https://github.com/mongodb-js/mongosh/pull/2229

      Problem Statement/Rationale

      When running the aggregate function over a collection, you can send a single aggregation stage without inserting it inside an array. For instance, the following example works properly:

      > db.collA.aggregate({$match:{}})
      

      However, it's not possible to run a single aggregation stage over a database:

      > db.aggregate({$listLocalSessions: {}})
      TypeError: e.some is not a function

      Steps to Reproduce

       > db.aggregate({$listLocalSessions: {}})

      Expected Results

      I would expect either to receive an error explaining that aggregate() is expecting an array, or to execute the aggregation with a single aggregation stage.

      Actual Results

      We return a misleading error:

       TypeError: e.some is not a function

       

            Assignee:
            gagik.amaryan@mongodb.com Gagik Amaryan
            Reporter:
            silvia.surroca@mongodb.com Silvia Surroca
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: