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

Is it possible to limit the results of a group function?

    XMLWordPrintableJSON

Details

    • Icon: Question Question
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Aggregation Framework
    • None

    Description

      Is it possible to limit the results of group function? I have a huge dataset and I want to group the results by an id and for each id to create an array with coordinates.

      The output result is:

      {u'_id': u'229136000', u'COORDINATES': [[160.6752, -27.80978]]} \{u'_id': u'567014500', u'COORDINATES': [[128.1873, -3.672835], [128.1876, -3.673245]]}
      ...
      

      As I see the code groups all the id's in dataset and the performance is very bad.

      Code:

      getPositionsOfshipsgrouped = db.collection.aggregate([ { "$group" :
      {"_id" :
        "$properties.MMSI",
        "total": {"$sum": 1},
        "COORDINATES": { "$push": "$geometry.coordinates"} }},
      {"$match": {"total":{"$gte": 0}}} ])
      

      If I add $limit in the end of this query, the group function executed and then the limit so there is no change in performance.

      Is it possible to limit the results of a group function?

      Attachments

        Activity

          People

            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            antonis_mak2411 AntonisMak
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: