I assume that you are running Meteor on Linux or Mac. If this is not the case, the code may not work.
The most obvious reason is that the mongo database does not contain any posts documents. What is the result:
$ mongo > use autana_dev > db.posts.find({}).count()
If the output is not null or 0 , you may need to connect with a username and password.
export MONGO_URL="mongodb://user: password@localhost :27017/autana_dev
If this does not help, I would try adding a bit of logging to see if messages were sent or not received:
Meteor.publish('posts', function() { console.log("returning " + Posts.find({}).count() + " posts"); return Posts.find(); });
and if the number is greater than 0 on the client
var postsHandle = Meteor.subscribe('posts'); Template.main.posts = function() { if( postsHanlde.ready() ){ console.log("I have " + Posts.find({}).count() + " posts on the client"); return Posts.find(); } };
the if( postsHanlde.ready() ) condition if( postsHanlde.ready() ) ensures that you don’t try to show posts until they arrive.
If you have documents in your mongodb but nothing is selected in Meteor, your mongodb may not work correctly.
Easy enough to check by replacing mongodb with an online solution. Create a free account on mongolab and change your MONGO_URL to the one set by the mongolab console. Insert some messages there and check again.
If you still do not have documents, then ...
That’s all I can come up with with your input. Hope this helps.
source share