Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 3.1.6
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Backwards Compatibility:
      Minor Change
    • Sprint:
      Quint Iteration 4, Quint Iteration 5, Quint Iteration 6

      Description

      Aggregation $project stage should support $slice operator on array fields similar to $slice in projection and syntax similar to aggregation $substr operator:

      { "$project" : { "newArray" : { "$slice" : [ "$oldarray" , 10, 4 ] } } }
      

      The above would take 4 elements from oldarray starting at position 10 (akin to "skipping first ten elements, as position is 0 based).

      Original description:

      If I have a document with an array of values in it, I would like to be able to project a slice of those values while aggregating.

      { title: "A doc",
        intervals: [
          { value: 1, foo: true, bar: false },
          { value: 2, foo: false, bar: true },
          { value: 3, foo: true, bar: false}
        ]
      }
      

      $project with a $slice should work as expected:

      { $project : {
          title: 1,
          fewerIntervals: {intervals:{$slice:2}}
        }
      }
      

      results in a pipelined document =>

      { title: "A doc",
        fewerIntervals: [
          { value: 1, foo: true, bar: false },
          { value: 2, foo: false, bar: true }
        ]
      }
      

      Similarly, the remainder of the existing $slice syntax should work as expected.

      { $project : {
          title: 1,
          fewerIntervals: {intervals:{$slice:[1,1]}}
        }
      }
      

      should produce

      { title: "A doc",
        fewerIntervals: [
          { value: 2, foo: false, bar: true }
        ]
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                58 Vote for this issue
                Watchers:
                48 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: