0

I have a field in my MongoDB documents called groupKey.

I want to get back a list of items (easy) but I don't want any groupKey to appear more than 22 times. The total number of documents returned can be many more than 22, however each group (which has a unique groupKey) should only have 22 documents returned.

Is this possible?

I can't seem to find anything that suggests it is, if you can point me to some docs or tell me what to search that would be helpful.

Ankur
  • 50,282
  • 110
  • 242
  • 312
  • 2
    This is probably a duplicate of http://stackoverflow.com/questions/24594049/mongodb-aggregation-pipeline-how-to-limit-a-group-push . In a few words MongoDB doesn't support this, i.e. limiting results per group. MongoDB and especially the aggregation framework work as a pipeline i.e. you can limit the results of the whole previous step, not limit the number of the sub-results of the previous step. – Mike Argyriou Sep 07 '15 at 14:14
  • 1
    Agree with @mike-argyriou.. You can't do it in Mongodb.. Better to do it in Java after retrieving the results.. – Darshan Mehta Sep 07 '15 at 14:22

0 Answers0