Closed johngonzalez closed 8 years ago
You are fine!. With findOne instead find I get the follow error: But. Why is not possible I use findOne?, I want to find a single document, should be possible use it appropriately named findOne. I self answer the question: Publications need return a cursor (find), not a object (findOne). According with meteor documentation (http://docs.meteor.com/#/full/findone) findOne is Equivalent to find(selector, options).fetch()[0] with options.limit = 1.
So I change the code in publications/posts.js to:
Meteor.publish('posts.single', function (postId) {
check(postId, String);
const selector = {_id: postId};
// here the change
const options = {limit: 1};
return Posts.find(selector, options);
//
});
It works! and I think that it is more efficient :)
I think is better use findOne instead find to fetch the post https://github.com/mantrajs/mantra-sample-blog-app/blob/master/server/publications/posts.js