I’m using Meteor 1.6. I created a collection called ‘Post’ and when I go to the console window and try to insert data as in "Post.insert({content: ‘my post’}) and press enter it return the unique id suggesting insert is success. But when I type "Post.find().count()"it returns 0 instead of 1. Where am I going wrong? This is how it goes:
I’m new to Meteor, so please bear with me I’m following a tutorial, and in that the insert worked fine for the instructor and he didn’t mention anything about publications and subscriptions. May I know how to set up.
It’s possible that the instructor had different set of packages installed. Probably he had autopublish and insecure and you don’t. And no, please don’t install them back, keep them out of your code, just set the publications and subscriptions up.
What happens when you don’t have the correct publications and subscriptions set up (and aren’t using the autopublish package) Is that the documents first get inserted into both the server database and the client database. Then the server sends a database update to the client, but if your publications/subscriptions aren’t set up correctly, the client doesn’t have access to the documents, which means that the server will say to the client that its current subscription has zero results, and the client will then remove the documents from its local database.
I setup publish/subscribe and tried the execution again, Again same result, but interestingly meteor informs that since autopublish is still installed, I remove it if I want to go ahead with publish and subscribe. So my question is if autopublish was turned on then why did I get the above error at all.
“Learn Web Development by Creating a Social Network” by Pablo Farias at Udemy. His teaching is pretty well and so far I didnt encounter any errors, and I’m more than 70% through the course. Ofcourse now I got stuck though!
So I tried to import Post.js file at both client and server in main.js and it worked. The above problem seems to be resolved, i.e insert works, count return right value.
So I tried to get that displayed on my browser using following code: