Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-2130

Ability to use Limit() with Distinct()

    Details

      Description

      Ability to use Limit() with Distinct()... or any of the cursor methods for the matter (sort, count, skip, etc. although limit has the biggest impact).

      Apparently there is no simple way to currently perform the following SQL query:

      SELECT DISTINCT(myField) FROM myTable WHERE x = y LIMIT(20)

      The current Distinct() implementation only allows for bringing back ALL distinct values in the collection or matching a query, but there is no way to limit these results. This would be very convenient and there are many use cases.

        Activity

        Hide
        gerhardb Gerhard Balthasar added a comment -

        Using distinct with sort would be my biggest hope for 1.9.0 apart from limit.

        Show
        gerhardb Gerhard Balthasar added a comment - Using distinct with sort would be my biggest hope for 1.9.0 apart from limit.
        Hide
        dominik Dominik Gehl added a comment -

        Sort() with Distinct() could also be very useful, for example in the following case:

        Email messages and attachments (attachments saved in an array inside the email message document).
        Getting the distinct list of attachment names ordered by message date would ask for the distinct on 'attachment name', but with a sort on 'message date'.

        Show
        dominik Dominik Gehl added a comment - Sort() with Distinct() could also be very useful, for example in the following case: Email messages and attachments (attachments saved in an array inside the email message document). Getting the distinct list of attachment names ordered by message date would ask for the distinct on 'attachment name', but with a sort on 'message date'.
        Hide
        jhgustafsson Johan Gustafsson added a comment -

        Is this feature resolved yet? If not, is it planned for any version? (and is the PHP-driver likely to be updated soon after?)

        Show
        jhgustafsson Johan Gustafsson added a comment - Is this feature resolved yet? If not, is it planned for any version? (and is the PHP-driver likely to be updated soon after?)
        Hide
        ian@10gen.com Ian Whalen added a comment -

        Johan Gustafsson this has not been completed yet, and it isn't scheduled for the upcoming 2.4 release. We will re-evaluate this for upcoming releases as we begin preparing them.

        Show
        ian@10gen.com Ian Whalen added a comment - Johan Gustafsson this has not been completed yet, and it isn't scheduled for the upcoming 2.4 release. We will re-evaluate this for upcoming releases as we begin preparing them.
        Hide
        sosh bg added a comment -

        Very surprised I couldn't do this. Last comment Sept 2012! Any update?

        Show
        sosh bg added a comment - Very surprised I couldn't do this. Last comment Sept 2012! Any update?
        Hide
        ivan.fioravanti@4ward.it Ivan Fioravanti added a comment -

        Any news on this feature request? It is quite useful in some scenario.

        Show
        ivan.fioravanti@4ward.it Ivan Fioravanti added a comment - Any news on this feature request? It is quite useful in some scenario.
        Hide
        mozillazg mozillazg added a comment -

        Is there any news about this feature request?

        Show
        mozillazg mozillazg added a comment - Is there any news about this feature request?
        Hide
        asya Asya Kamsky added a comment -

        This can be done using aggregation framework as

        db.collection.aggregate([{$match:{<your-filter>}}, {$group:{_id:null, myField:{$addToSet:"$myField"}}},{$limit:20}])

        Show
        asya Asya Kamsky added a comment - This can be done using aggregation framework as db.collection.aggregate([{$match:{<your-filter>}}, {$group:{_id:null, myField:{$addToSet:"$myField"}}},{$limit:20}])

          People

          • Votes:
            45 Vote for this issue
            Watchers:
            32 Start watching this issue

            Dates

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