Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Minor - P4 Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3.2
    • Component/s: Write Ops
    • Labels:
      None
    • Backport:
      No
    • # Replies:
      36
    • Last comment by Customer:
      true
    • Documentation changes needed?:
      Done

      Description

      You can now limit the resulting elements in the array after you push. The new syntax is :

      db.coll.update({...}, {$push: { $each:[<values>], $slice:-N, $sort:{...}}}
      

      The initial implementation (see SERVER-8069 for more) only supports negative slice (taking stuff from the end of the array).

      Sorting is by embedded document fields and doesn't work any type which is not an embedded docs (in the array).

        Issue Links

          Activity

          Hide
          auto
          added a comment -

          Author:

          {u'date': u'2012-12-12T21:21:43Z', u'email': u'alerner@10gen.com', u'name': u'Alberto Lerner'}

          Message: SERVER-991 Allowed trimTo to be a double if it's not fractional.
          Branch: master
          https://github.com/mongodb/mongo/commit/7bf153e956d24bad98169ef751ff71050cce10dd

          Show
          auto
          added a comment - Author: {u'date': u'2012-12-12T21:21:43Z', u'email': u'alerner@10gen.com', u'name': u'Alberto Lerner'} Message: SERVER-991 Allowed trimTo to be a double if it's not fractional. Branch: master https://github.com/mongodb/mongo/commit/7bf153e956d24bad98169ef751ff71050cce10dd
          Hide
          auto
          added a comment -

          Author:

          {u'date': u'2012-12-13T18:48:38Z', u'email': u'alerner@10gen.com', u'name': u'Alberto Lerner'}

          Message: SERVER-991 Fixed the last few trim's to trimTo's.
          Branch: master
          https://github.com/mongodb/mongo/commit/2beeb14b6a200094ccf1ebe3be638a8c0d00f843

          Show
          auto
          added a comment - Author: {u'date': u'2012-12-13T18:48:38Z', u'email': u'alerner@10gen.com', u'name': u'Alberto Lerner'} Message: SERVER-991 Fixed the last few trim's to trimTo's. Branch: master https://github.com/mongodb/mongo/commit/2beeb14b6a200094ccf1ebe3be638a8c0d00f843
          Hide
          auto
          added a comment -

          Author:

          {u'date': u'2013-01-03T17:19:13Z', u'name': u'Alberto Lerner', u'email': u'alerner@10gen.com'}

          Message: SERVER-991 SERVER-8008 Replaced $trimTo by $slice (but only accepting negative slices for now).
          Branch: master
          https://github.com/mongodb/mongo/commit/b3687e73545f6d0d04f1992119308e7ab80d44e1

          Show
          auto
          added a comment - Author: {u'date': u'2013-01-03T17:19:13Z', u'name': u'Alberto Lerner', u'email': u'alerner@10gen.com'} Message: SERVER-991 SERVER-8008 Replaced $trimTo by $slice (but only accepting negative slices for now). Branch: master https://github.com/mongodb/mongo/commit/b3687e73545f6d0d04f1992119308e7ab80d44e1
          Hide
          auto
          added a comment -

          Author:

          {u'date': u'2013-01-03T21:23:09Z', u'name': u'Alberto Lerner', u'email': u'alerner@10gen.com'}

          Message: SERVER-991 SERVER-8008 Fixed test to use $slice instead of $trimTo.
          Branch: master
          https://github.com/mongodb/mongo/commit/56090cce56cc8e700b8dedc809e50523d3272cea

          Show
          auto
          added a comment - Author: {u'date': u'2013-01-03T21:23:09Z', u'name': u'Alberto Lerner', u'email': u'alerner@10gen.com'} Message: SERVER-991 SERVER-8008 Fixed test to use $slice instead of $trimTo. Branch: master https://github.com/mongodb/mongo/commit/56090cce56cc8e700b8dedc809e50523d3272cea
          Hide
          Flavien
          added a comment -

          Is there a chance to have this work with the aggregation framework in a $group operator, so that we can find the top K items in each group?

          Show
          Flavien
          added a comment - Is there a chance to have this work with the aggregation framework in a $group operator, so that we can find the top K items in each group?

            People

            • Votes:
              141 Vote for this issue
              Watchers:
              102 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                39 weeks, 5 days ago
                Date of 1st Reply: