How to return some parts of collection in method call?

Hello everyone,

I’m trying to return some parts of collection in response to a method call but the call doesn’t get into the callback, here is the code :

'SomePosts'(pid){
    var somePosts = Posts.find({'postId': pid});
    return somePosts;
}

Is this type of collection finding inside a method correct ?

Should I do any changes regarding the publish of collection ? Because in publish I have limited the number to 100 posts.

You cannot return a cursor using a method. You’ll need to convert the cursor to an array first:

SomePosts(pid) {
  const somePosts = Posts.find({'postId': pid}).fetch();
  return somePosts;
}
1 Like