I uninstalled the autosubscribe and restarted the meteor app. Since then, I haven't been able to access my collection data on the client.
Every question related to the empty array return comes up with the same answer: the subscribed data isn't available yet. But no matter how long I wait I never see the data on the client.
Server:
Meteor.startup(function () {
Meteor.publish("states", function () {
return states.find();
});
});
Logging states.find().fetch()
on the server spits out my states as expected.
On the client:
Meteor.subscribe("states", function(){
console.log(states, states.find(), states.find().fetch());
});
states
and states.find()
return objects as expected, .fetch()
returns an []
.
Waiting (even several minutes) then running states.find().fetch()
in the browser console gives me []
still.
Thoughts?
EDIT
Collection is declared outside of the isServer/isClient blocks (to utilize schemas).
states = new Meteor.Collection("states");
I think you are getting
[]
because you are publishing the data on the startup, when isn't ready, lets make that subscribe reactive.OPTIONAL
There is no reason to declare the collections inside the
isServer/isClient
if statementsSince you are starting with the Good practices (removing
insecure/autopublish
packages)Lets do the follow.
First Create the folder structure. (check meteor/structuringyourapp and this SO).
Inside the
appName/lib/collection.js
put this code.and on the
appName/server/publish.js