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

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.3
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Backwards Compatibility:
      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

              • Votes:
                21 Vote for this issue
                Watchers:
                20 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: