Can't add new post after added publish and subscribe?


#1

Can’t add new post after added publish and subscribe ?


#2

Can you please provide a few more details? Basically, publish and subscribe have nothing to do with Inserting/adding. They just decide what you can read/see from the already added posts.


#3

I want to insert a document into a collection Posts. Should I insert into the collection with subscribed ( $meteor.collection(Nodes).subscribe(‘nodes’); ) or $meteor.collection(Posts) ?


#4

Make sure you have create a collection called Posts in the /lib folder.
Then just do Posts.insert({title: “Post Title”, message: “Post Message”}).

Or to be more safe, split the code into Client and Server side.
On the sever side create a method like this:

Meteor.methods({
    insertPost : function(newPost) {
       Posts.insert({title: newPost.title, message: newPost.message})
    }
});

And on the Client side pass a new pos to that method like:

var newPost = { title: "Your post title", message: "Your message" };
Meteor.call('insertPost', newPost);