Is there a way to retrieve a specific array slice directly from MongoDB? I am attempting to achieve something similar to this: Model.find({filter: option}, startindex, endindex. Currently, the only method I have discovered is as follows:
let result = await Model.find({filter: option});
returh result.slice(startIndex, endIndex)
Unfortunately, this approach is not effective as it requires fetching the entire record each time. If there is a way to accomplish this at the MongoDB level, I would greatly appreciate your guidance. Thank you in advance!
UPDATE: After conducting further research, I have come across a potential solution:
Model.find({filter: option}).skip(skip).limit(limit);
It appears that using this method allows me to slice the document array directly within MongoDB. If you have any other suggestions or ideas, please feel free to share them. Thank you!