Search code examples
mongodbmeteoriron-routermongo-collection

Meteor : passing router parameter to get Collection data without results


I'm fairly new to meteor and have encountered a problem while trying to use Iron Router to pass a url parameter to a Collection and retrieve some data for display.

Specifically, I have a Collection with events and I'd like to have a page that display a single one in more detail.

PS: I've used Iron Router and Meteor's publish/subscribe logic succesfully for other tasks, such as displaying all events, creating them and saving them to a personal list.


event.html

<template name="event">
  <div class="page-header">
    <h1>{{title}}</h1>
  </div>
  <div class="container">
    <p>{{content}}</p>
  </div>
</template>

router.js

this.route('event',{
    path: '/event/:_id',
    waitOn: function () {
        return Meteor.subscribe('Events');
    },
    data: function () {
        return Events.findOne(this.params._id);
    }
});

Publishing happens on the server in publish.js and subscribing in the router
publish.js

Meteor.publish('Events', function () {
    return Events.find();
});

router.js

Router.configure({

    (..)

    waitOn: function() {
        return [
          Meteor.subscribe('Events'),
          Meteor.subscribe('myEvents')
        ];
    }
});

I've been looking at this tutorial by Manuel Schoebel link

All is fine up until the point where the Collection lookup is happening. When I log the result data from the Collection, it's undefined

data: function () {
    var event = Events.findOne(this.params._id);
    console.log(event);
    return event;
}

Solution

  • Mistakenly, I placed a : where it should not have been.
    Closing question.