Reputation: 1
I'm quite new in javascript programing, so I really appreciate any help.
I'm using:
Meteor (official Windows port) latest version 1.1.0.2 with Iron Router and Autopublish package
What I'm trying to do, shouldn't be hard to do, but something is missing to me. I just want to load data from Mongo DB collection
Movies = new Mongo.Collection('movies');
into my template in /client folder
<template name="movie_template">
<p>Dynamic page test with movieID {{id}}</p>
<h1>{{name}}</h1>
<p>{{year}}</p>
</template>
my router.js file based in /lib folder in root of my Meteor project
Router.route('/movies/:movieId', function() {
this.render('movie_template', {
waitOn: function() {
return Meteor.subscribe('moviesDetails', this.params.movieId);
},
data: function() {
return Movies.findOne({id: this.params.movieId});
}
});
});
publications.js in /server folder
Meteor.publish('movieDetails', function(movieID) {
check(movieID, Number);
return Movies.find({id: movieID});
});
Only one thing what I get is paragraph text without ID. What I'm doing wrong?
Side question: Do I have to use publish() function while I'm using Autopublish package? In that case just use Movies.find() instead subscribe()?
NOTE: this is my Movie object field keys.
{_id, id, name, year}
Upvotes: 0
Views: 314
Reputation: 61
@below9k is correct and you should be using _id
rather than id
.
To answer your side question, with the autopublish package
it is not necessary to do either Meteor.publish and Meteor.subscribe
Upvotes: 0