title: MongoDB lists - get every Nth item
body: <p>I have a Mongodb schema that looks roughly like:</p>
  
  <pre><code>[
    {
      "name" : "name1",
      "instances" : [ 
        {
          "value" : 1,
          "date" : ISODate("2015-03-04T00:00:00.000Z")            
        }, 
        {
          "value" : 2,
          "date" : ISODate("2015-04-01T00:00:00.000Z")
        }, 
        {
          "value" : 2.5,
          "date" : ISODate("2015-03-05T00:00:00.000Z")
        },
        ...
      ]
    },
    {
      "name" : "name2",
      "instances" : [ 
        ...
      ]
    }
  ]
  </code></pre>
  
  <p>where the number of instances for each element can be quite big.</p>
  
  <p>I sometimes want to get only a sample of the data, that is, get every 3rd instance, or every 10th instance... you get the picture.</p>
  
  <p>I can achieve this goal by getting all instances and filtering them in my server code, but I was wondering if there's a way to do it by using some aggregation query.</p>
  
  <p>Any ideas?</p>
  
  <hr>
  
  <p><strong>Updated</strong></p>
  
  <p>Assuming the data structure was flat as @SylvainLeroux suggested below, that is:</p>
  
  <pre><code>[
    {"name": "name1", "value": 1, "date": ISODate("2015-03-04T00:00:00.000Z")},
    {"name": "name2", "value": 5, "date": ISODate("2015-04-04T00:00:00.000Z")},
    {"name": "name1", "value": 2, "date": ISODate("2015-04-01T00:00:00.000Z")},
    {"name": "name1", "value": 2.5, "date": ISODate("2015-03-05T00:00:00.000Z")},
    ...
  ]
  </code></pre>
  
  <p>will the task of getting every Nth item (of specific <code>name</code>) be easier?</p>