Robomongo : Exceeded memory limit for $group

It is always better to use match before group when you have large data. If you are using match before group, you won't get into this problem.

   {$match:{State:'TAMIL NADU'}},
       _id:{DiseCode:"$code", State:"$State"},




If you really overcome this issue without match, then solution is { allowDiskUse: true }

{ allowDiskUse: true } 

Should be placed right after the aggregation pipeline.

In your code this should go like this:

  // Group on unique value storing _id values to array and count 
  { "$group": {
    "_id": { RegisterNumber: "$RegisterNumber", Region: "$Region" },
    "ids": { "$push": "$_id" },
    "count": { "$sum": 1 }      
  // Only return things that matched more than once. i.e a duplicate
  { "$match": { "count": { "$gt": 1 } } }
], { allowDiskUse: true } )

Note: Using { allowDiskUse: true } may introduce issues related to performance as aggregation pipeline will access data from temporary files on disk. Also depends on disk performance and the size of your working set. Test performance for your use case