Details

    • Backport:
      No
    • # Replies:
      4
    • Last comment by Customer:
      true

      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
          William Newman
          added a comment -

          Any good work arounds for this issue? Really don't want to pull back millions of array values into memory to do the slice there. And map reduce is too slow.

          Show
          William Newman
          added a comment - Any good work arounds for this issue? Really don't want to pull back millions of array values into memory to do the slice there. And map reduce is too slow.
          Hide
          Sergey Smirnov
          added a comment -

          It's really necessarry thing!

          Show
          Sergey Smirnov
          added a comment - It's really necessarry thing!
          Hide
          Pinte
          added a comment -

          need it too

          Show
          Pinte
          added a comment - need it too
          Hide
          Antonio Quintana
          added a comment -

          My use case:

          I'm trying to get the top (and bottom) N cities, sorted by population and grouped by year.

          After some $sorts's, $group's and $push's, I've got something like this:

          {_id: "2013",
          cities:["MEX", "CUN", "MIA", "JFK", "LHR", ...]
          },
          { _id: "2014",
          cities:["MEX", "MIA", "GCM", "JFK", "DFW", ...]]
          }
          .. and so on

          Now, I want to do perform {$project: {cities: {$slice: N}}}

          I think the $project operator should accept all of the operators the projection document does in the find() command

          Show
          Antonio Quintana
          added a comment - My use case: I'm trying to get the top (and bottom) N cities, sorted by population and grouped by year. After some $sorts's, $group's and $push's, I've got something like this: {_id: "2013", cities: ["MEX", "CUN", "MIA", "JFK", "LHR", ...] }, { _id: "2014", cities: ["MEX", "MIA", "GCM", "JFK", "DFW", ...] ] } .. and so on Now, I want to do perform {$project: {cities: {$slice: N}}} I think the $project operator should accept all of the operators the projection document does in the find() command

            People

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

              Dates

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