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

XMLWordPrintableJSON

    • Type: Question
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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?

            Assignee:
            Ramon Fernandez
            Reporter:
            AntonisMak
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: