[SOLVED]: Discover Meteor: Comments - Unexpected Token


#1

I am at the end of Chapter 10. I have run into an error when adding commentsCount property to Posts. I initially checked over my work when I entered these changes to see if I had typos. I couldn’t find any, so I copy and pasted the code from the book, and the same error exists.

=> Modified – restarting.
=> Errors prevented startup:

While processing files with ecmascript (for target os.osx.x86_64):
server/publications.js:7:2: Unexpected token (7:2)

=> Your application has errors. Waiting for file change.

// Fixture data
if (Posts.find().count() === 0) {
  var now = new Date().getTime();

  // create two users
  var tomId = Meteor.users.insert({
    profile: { name: 'Tom Coleman' }
  });
  var tom = Meteor.users.findOne(tomId);
  var sachaId = Meteor.users.insert({
    profile: { name: 'Sacha Greif' }
  });
  var sacha = Meteor.users.findOne(sachaId);

  var telescopeId = Posts.insert({
    title: 'Introducing Telescope',
    userId: sacha._id,
    author: sacha.profile.name,
    url: 'http://sachagreif.com/introducing-telescope/',
    submitted: new Date(now - 7 * 3600 * 1000),
    commentsCount: 2
  });

  Comments.insert({
    postId: telescopeId,
    userId: tom._id,
    author: tom.profile.name,
    submitted: new Date(now - 5 * 3600 * 1000),
    body: 'Interesting project Sacha, can I get involved?'
  });

  Comments.insert({
    postId: telescopeId,
    userId: sacha._id,
    author: sacha.profile.name,
    submitted: new Date(now - 3 * 3600 * 1000),
    body: 'You sure can Tom!'
  });

  Posts.insert({
    title: 'Meteor',
    userId: tom._id,
    author: tom.profile.name,
    url: 'http://meteor.com',
    submitted: new Date(now - 10 * 3600 * 1000),
    commentsCount: 0
  });

  Posts.insert({
    title: 'The Meteor Book',
    userId: tom._id,
    author: tom.profile.name,
    url: 'http://themeteorbook.com',
    submitted: new Date(now - 12 * 3600 * 1000),
    commentsCount: 0
  });
}

Anyone know what is wrong here?


#2

So the error references line 7 of server/publications.js - what does that file look like?


#3

Hi there. Big oversight on my end…I feel silly :stuck_out_tongue:

This is what I had:

Meteor.publish('comments', function() {
  check(postId, String),
  return Comments.find({postId: postId});
});

And this is how it should be:

Meteor.publish('comments', function(postId) {
  check(postId, String);
  return Comments.find({postId: postId});
});