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

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.3
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Fully Compatible

      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 .

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

              Created:
              Updated:
              Resolved: