I have this schema:
article: {
subject,
comments: []
}
if I have 8 comments, and query
article.find({}, {
comments: {
$slice: [ -10, 5 ]
}
});
And I get comments from index 0 to index 4,
but I only want comments from index 0 to index 2 to be returned because of paging.
(page 1 $slice[ -5, 5 ] from index 3 to index 7, page 2 $slice[ -10, 5 ] from index 0 to index 2)
now I have to pass another parameter "lastId" to compare each comments and remove that "_id" < "lastId", but I think it is a little hacky.
Any one has a good solution for this?