I am novice to meteor js. To discover I created a small application. I created a collection ‘posts’ with a title, contents and a reference section (rubrique) and a collection ‘rubrique’. I manage to publish the whole collection or all posts by section but i can’t publish for a single post. I put you down the script. If somebody can help me thank you in advance.
//publish all or by section
Meteor.publish(‘posts’, function (option) {
if (option == “all”) {
return Posts.find();
} else {
return Posts.find({ref: option});
}
//server for single post
Meteor.publish(‘single-post’, function (postId) {
check(postId, { _id: String }); return Posts.find({}, options);
});
thank you for your reply, I added the limit but nothing changes. i tried to play the request on console of my web browser after click on ‘single-post’ for testing.
Thank you very much in all for your answer, I simplified the publication and i modified the subscrition too. I think that the code is not great clean but it works well. I leave a code for informations
// On server
//Ensemble des Posts, on passe un parametre ‘all’ pour tous les posts ou ‘ref’ pour avoir posts par rubriques
Meteor.publish(‘posts’, function (option) {
if(option == “all”){
return Posts.find();
}else{
return Posts.find({ref: option});
}
});
//On remonte la collection rubriques
Meteor.publish(‘rubriques’, function () {
return Rubriques.find();
});