I am storing post comments in a post, and the problem I am facing right now is that I cannot use limit with skip on an array of a document, since the users can post as many comments as they want, the array will be huge, So i wanted to paginate the comments.

is there a way to accomplish this?

is it possible to only retrieve like 10 comments per call?

thanks!

{
  id:0,
  ref:0,
  type: 'image',
  date: null,
  title: 'this is my title',
  comments:[
      {
        user : 'myUser',
        text : 'text'
      },
      {
        user : 'myUser2',
        text : 'text2'
      }
}
有帮助吗?

解决方案

Found the solution: in projections just do :

projection("{comments : {$slice:[#,#]}}",start,size)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top