Meteor’s Autopublish Package

If you create Meteor project from scratch(i.e using meteor create), it will automatically have the autopublish package enabled.

The goal of autopublish package is to make it very easy to start coding with Meteor, and it does this by automatically mirroring all the data from the server to client, thus taking care of publications and subscriptions for you.

Suppose you have a collection called ‘posts’ on the server. Thenautopublish will automatically send every post that it finds in the Mongo posts collection into a collection called ‘posts’ on the client (assuming there is one).

But there are obvious problems with having a complete copy of your app’s database cached on every user’s machine.

For this reason, autopublish is only appropriate when you are starting out, and haven’t yet thought about publications.

Once you remove autopublish , you’ll quickly realize that all your data has vanished from the client. Type

[cc lang=”javascript”]
meteor remove autopublish
[/cc]
An easy way to get it back is to simply duplicate what autopublish does, and publish a collection in its entirety. For example:
[cc lang=”javascript”]
Meteor.publish(‘allPosts’,function(){
returnPosts.find();
});
[/cc]


Posted

in

, ,

by

Recent Post

Click to Copy