How to use the subscribe that it has only one item?

Meteor.publish('postDetails', function(postId) {
    return Posts.find(postId);
    // In fact, I want to findOne

var postDetails = $meteor.collection(Posts).subscribe('postDetails', postId);

How to get the data I want from postDetails ?


where you got that ugly long subscribe sentence?
postDetails is just handle pointing to subscription.
after subscription is ready, you can access the post for example
It should work in browser console.

Still why not Meteor.subscribe('postDetails', postId); ?


Could you tell more details ?


Subscribe itself does not return document. It returns only handle on which you can call .stop() to end subscription.
To get data, you need to query client side collection and for this Posts.findOne() should work for you.


I got undefined from Posts.findOne() ?


I am using Angular-Meteor


you need to define which One you want to find.

Posts.findOne({_id: "ysywiwwhs"})


Posts.findOne({age:{$gt: 50}})

now your collection can contain many documents with age>50, but this will only return the first of the documents it finds.


if it is only a one item you’d like to retrieve why not use this msavin:fetcher package. you still need to make a proper publish function though which I think where you are having problem