Search code examples
mongodbmeteormongodb-querymeteorite

Get MongoDB objects between a given range indexes


How can i fetch the mongodb objects from a starting index to an end index. For example I have 100 objects and i want to get these objects first 1 to 10 then 11 to 20 and then 21 to 30. How can I write a mongodb query which returns me the objects 11 to 20. Thanx

My code is

Template.syllabus_design.topics = function () {
    var syllabus = Meteor.syllabi.findOne(Session.get("currentSyllabusId"));
    topics= Meteor.topics.find({subject_id: syllabus.subject_id, level_id: syllabus.level_id})
return topics 

}


Solution

  • You just need to use the limit and skip options in your query. For items 11-20, you would need:

    myCollection.find({myquery}, {skip: 10, limit: 10});