Domanda

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'
      }
}
È stato utile?

Soluzione

Found the solution: in projections just do :

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top