Details

    • Type: New Feature
    • Status: In Code Review
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 2.1.1
    • Fix Version/s: 3.1.6
    • Component/s: Aggregation Framework
    • Labels:
      None

      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 }
        ]
      }
      

        Issue Links

          Activity

          Hide
          newmanw William Newman added a comment -

          Gentle bump to ask if there are plans to implement this. Possible $limit on $push might help as well.

          Show
          newmanw William Newman added a comment - Gentle bump to ask if there are plans to implement this. Possible $limit on $push might help as well.
          Hide
          asya Asya Kamsky added a comment -

          William Newman we are aware of the desirability of this feature - we are definitely considering it (or possibly one of several similar requests that have some overlap - SERVER-4589 and SERVER-9377) for upcoming releases.

          Show
          asya Asya Kamsky added a comment - William Newman we are aware of the desirability of this feature - we are definitely considering it (or possibly one of several similar requests that have some overlap - SERVER-4589 and SERVER-9377 ) for upcoming releases.
          Hide
          SamV Sam Verschueren added a comment -

          Is there a workaround for this issue? I have a lot of data and I only need the 10 first elements in the array when I aggregate.

          Show
          SamV Sam Verschueren added a comment - Is there a workaround for this issue? I have a lot of data and I only need the 10 first elements in the array when I aggregate.
          Hide
          yoo yogesh added a comment -

          Any one found solution regarding this ?

          Show
          yoo yogesh added a comment - Any one found solution regarding this ?
          Hide
          ramon.fernandez Ramon Fernandez added a comment -

          All, as you can see in the "Fix Version/s" field this functionality has been scheduled for the upcoming development release 3.1.4, due in the coming weeks. At the time of this writing this feature is in code review, so we expect to be able to merge the code into master very soon.

          Regards,
          Ramón.

          Show
          ramon.fernandez Ramon Fernandez added a comment - All, as you can see in the "Fix Version/s" field this functionality has been scheduled for the upcoming development release 3.1.4, due in the coming weeks. At the time of this writing this feature is in code review, so we expect to be able to merge the code into master very soon. Regards, Ramón.

            People

            • Votes:
              57 Vote for this issue
              Watchers:
              46 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since reply:
                3 weeks, 4 days ago
                Date of 1st Reply:

                Agile