I need to use mongodb's $limit in the aggregation but I wanted to add a document limiting condition. But I don't know if this is possible.
Example:
db.collection.find()
{"type": "one"}
{"type": "two"}
{"type": "one"}
{"type": "three"}
{"type": "one"}
{"type": "three"}
db.collection.aggregation([ ... ])
Result I need the aggregation:
{"type": "one"}
{"type": "two"}
{"type": "one"}
{"type": "three"}
{"type": "three"}
In this case I need to limit the documents by type. And I wanted at most 2 documents of the same type. How could I do this?
Thanks in advance :)