MongoDB lists - get every Nth item

前端 未结 6 2367
太阳男子
太阳男子 2021-02-13 05:36

I have a Mongodb schema that looks roughly like:

[
  {
    \"name\" : \"name1\",
    \"instances\" : [ 
      {
        \"value\" : 1,
        \"date\" : ISODate         


        
6条回答
  •  深忆病人
    2021-02-13 05:47

    Or with just a find block:

    db.Collection.find({}).then(function(data) {
      var ret = [];
      for (var i = 0, len = data.length; i < len; i++) {
        if (i % 3 === 0 ) {
          ret.push(data[i]);
        }
      }
      return ret;
    });
    

    Returns a promise whose then() you can invoke to fetch the Nth modulo'ed data.

提交回复
热议问题