Need help -- Meteor.subscribe not working after deployment

I just started using Meteor, I have a test application that is using Meteor.subscribe(), [on client side], which works on my development computer, but not once I deploy to my server (Digital Ocean). I have been stuck on this for weeks.
Note1: In the client code I tried with and without fetch() and neither worked on the server.
Note2: I was able to get the code to run on the server, however, only if I built the code with the --debug flag, which I cannot use for application security.

What am I missing???
Thanks for the help!
Kerry

if (Meteor.isClient) {
Meteor.subscribe(‘tasks’);
ClientTasks = new Meteor.Collection(“tasks”);

Template.body.helpers({
tasks: function () {
return ClientTasks.find({}, {sort: {createdAt: -1}}).fetch();
}
});

if (Meteor.isServer) {
Meteor.publish(‘tasks’, function() {
return Tasks.find();
});

Not sure, if this helps, but I noticed some errors:

  • The collections have to be defined on client and server side alike, so you should place the collection creation in the global section of your code, i.e. outside of isClient() and isServer(), like this (will work on both sides):

const Tasks = Mongo.Collection('tasks');

  • Currently, your server code would have no reference to any collection, since you placed your collection declaration only in the isClient() code. This cannot work.
  • It’s Mongo.Collection, not Meteor.Collection

I simplified the application javascript, to remove the coding errors, however I am still getting the same problem as before, with the deployed code not working on the server, but still working on my development machine.
Below is the revised code:
Note 3: I am using meteor build to create the bundle/tarball for deployment.
Note 4: Now building with or without the --debug flag has no effect on the server.

// global section
const Tasks = new Mongo.Collection( ‘tasks’ );

if (Meteor.isClient) {
Meteor.subscribe(‘tasks’);
Template.body.helpers({
tasks: function () {
// Show newest tasks at the top
return Tasks.find({}, {sort: {createdAt: -1}});
}
});

if (Meteor.isServer) {
Meteor.publish(‘tasks’, function() {
return Tasks.find();
});

Review the first few sections of the Meteor Guide then go through the 1.3 version of the simple-todos Tutorial. It’ll answer a lot of questions about what the structure of your app should be with 1.3. You should be able to adapt the Tutorial code to your project. With 1.3 using ES2015 modules there’s a lot of changes to where things should go.

Where are you deploying to? If you’re using Galaxy, you have to have your Mongo setup elsewhere. I use Webfaction and have a github repo on how to set that up and deploy. I’ve updated apps from 1.2 to 1.3 with no trouble.

This item is now CLOSED as I am migrating to v1.3.

Thanks for the help!
Kerry