0

I'm new to mongo and using it in my nodejs application. I have a huge collection of entities. Out of which I have to find that entries from a specific array. I can find all the entities as :

dataModel.find({}, function(err, entities){
    if(err){
      res.json({message: err})
    }

    console.log(entities);
    res.json({entities});
  });

and then return a few (fromIndex to toIndex) which is highly un-optimized. How can I find only from fromIndex to toIndex.

[Edit: ] Suppose I have an entities array in database which is 10,000 in length and I need to find only first 10 entries and then upon user request the next entries and so on (pagination in UI), so what I can do is find all entries and return the first 10 (or some 10) which is not optimized. Is there anything like findFromIndex function which takes size of chunk (like 10) and returns only those 10 entries in the array?

Ajay Gaur
  • 5,140
  • 6
  • 38
  • 60

0 Answers0