Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-4899

aggregation: need an expression to give the size of an array in projections

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 2.5.3
    • Aggregation Framework
    • None
    • Fully Compatible

    Description

      Some analytics queries can't be done by the aggregation framework only for the lack of an array size operator:

      var a1 = db.runCommand({ aggregate:"track", pipeline:[
          {$group: {
              _id: "$urllower",
              visits: {$sum: "$visits"},
              kw: {$addToSet: "$kw"}
          },
           {$project: {
               urllower: "$_id",
               visits: 1,
               keywords: {$size: "$kw"}
           }
      ]});
      

      The request here is for the $size operator at the end of the projection, which would give the size of the keyword array being built up here.

      I choose $size for the name because we already use that for the same meaning here:
      http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24size .

      Attachments

        Issue Links

          Activity

            People

              matt.dannenberg Matt Dannenberg
              dan@mongodb.com Daniel Pasette (Inactive)
              Votes:
              21 Vote for this issue
              Watchers:
              20 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: