title: delete records from mongodb based on condition
body: <p>Hi I am new to mongodb and I don't know how can I achieve below efficiently as we have huge data in collection</p>
  
  <p>I want to delete those documents which are older than 6 month
  but same time I want to keep latest 5 record for each al_object_id even though there are older than 6 month.</p>
  
  <pre><code>+--------+---------------------+--------------+
  | al_id  |       al_date       | al_object_id |
  +--------+---------------------+--------------+
  | 224917 | 2012-01-01 00:00:00 |            1 |
  | 224918 | 2012-01-02 00:00:00 |            1 |
  | 224919 | 2012-01-03 00:00:00 |            1 |
  | 224920 | 2012-01-04 00:00:00 |            1 |
  | 224921 | 2012-01-05 00:00:00 |            1 |
  | 224922 | 2012-01-06 00:00:00 |            1 |
  | 224923 | 2012-01-07 00:00:00 |            1 |
  | 224925 | 2016-01-01 00:00:00 |          222 |
  | 224926 | 2016-01-02 00:00:00 |          222 |
  | 224927 | 2016-01-03 00:00:00 |          222 |
  | 224928 | 2016-01-04 00:00:00 |          222 |
  | 224929 | 2016-01-05 00:00:00 |          222 |
  | 224930 | 2016-01-06 00:00:00 |          222 |
  | 224931 | 2016-01-07 00:00:00 |          222 |
  | 224932 | 2016-01-08 00:00:00 |          222 |
  | 224933 | 2016-01-09 00:00:00 |          222 |
  | 224934 | 2016-01-10 00:00:00 |          222 |
  | 224935 | 2012-01-11 00:00:00 |          222 |
  | 224936 | 2012-01-12 00:00:00 |          222 |
  | 224937 | 2012-01-13 00:00:00 |          222 |
  | 224938 | 2012-01-14 00:00:00 |          222 |
  | 224939 | 2012-01-15 00:00:00 |          222 |
  | 224940 | 2012-01-16 00:00:00 |          222 |
  +--------+---------------------+--------------+
  </code></pre>
  
  <p>in case of record for object al_object_id  = 1 there is no new update in last 6 month so i want to keep latest 5 updates and remove others
  where as for al_object_id = 222 there are updates in last 6 month so i want to remove records older than 6 month. so expected output will be as below</p>
  
  <pre><code>+--------+---------------------+--------------+
  | al_id  |       al_date       | al_object_id |
  +--------+---------------------+--------------+
  | 224923 | 2012-01-07 00:00:00 |            1 |
  | 224922 | 2012-01-06 00:00:00 |            1 |
  | 224921 | 2012-01-05 00:00:00 |            1 |
  | 224920 | 2012-01-04 00:00:00 |            1 |
  | 224919 | 2012-01-03 00:00:00 |            1 |
  | 224934 | 2016-01-10 00:00:00 |          222 |
  | 224933 | 2016-01-09 00:00:00 |          222 |
  | 224932 | 2016-01-08 00:00:00 |          222 |
  | 224931 | 2016-01-07 00:00:00 |          222 |
  | 224930 | 2016-01-06 00:00:00 |          222 |
  | 224929 | 2016-01-05 00:00:00 |          222 |
  | 224928 | 2016-01-04 00:00:00 |          222 |
  | 224927 | 2016-01-03 00:00:00 |          222 |
  | 224926 | 2016-01-02 00:00:00 |          222 |
  | 224925 | 2016-01-01 00:00:00 |          222 |
  +--------+---------------------+--------------+
  </code></pre>