0

I am having trouble getting my very simple meteor tutorial to read my collections in Mongodb and print to the page. This is the official tutuorial found on meteor's website. Any help would be much appreciated. If anyone would like to connect to the workspace and make changes let me know and I can grant access.

Here is a link to my workspace: https://ide.c9.io/hilldesigns/meteor

Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
  tasks: function () {
    return Tasks.find({});
   }
 });
}

Here is the HTML markup:

<head>
<title>Todo List</title>
</head>

<body>
  <div class="container">
 <header>
  <h1>Todo List</h1>
 </header>
   <ul>
   {{#each tasks}}
     {{> task}}
   {{/each}}
  </ul>
</div>
</body>

<template name="task">
    <li>{{text}}</li>
</template>
5
  • Your helper defines "task" but your template uses "tasks". Commented Jan 12, 2016 at 14:46
  • I've tried that as well with no success @BrendanTurner Commented Jan 12, 2016 at 14:50
  • You can't attach a Template helper to the body like that. You have to make a template (maybe 'taskList') and include it via {{> taskList}} and then point your Template helper to taskList instead of body. Commented Jan 12, 2016 at 14:54
  • That's surprising because the code is copy and pasted from the meteor tutorial itself. Could you mock up some code of what you are saying? I am not sure what you are saying @BrendanTurner Commented Jan 12, 2016 at 15:03
  • Looking at the application url: meteor-hilldesigns.c9users.io for the above, I don't see an error there. Was the issue resolved? The accepted answer has comments that show that it didn't work, but then no reference to the actual solution that worked Commented Jan 13, 2016 at 12:17

3 Answers 3

1

Not sure about attaching a helper to the body, it's not supported in 1.2.1 ( the latest release ). If you open the console in your browser it should show an error about can't access helpers on undefined.

So, to make it work...

<head>
<title>Todo List</title>
</head>

<body>
  <div class="container">
 <header>
  <h1>Todo List</h1>
 </header>
   {{> todos}}
 </div>
</body>

<template name="todos">
  <ul>
  {{#each tasks}}
    {{> task}}
  {{/each}}
 </ul>
</template>

<template name="task">
    <li>{{text}}</li>
</template>

with

Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {
// This code only runs on the client
Template.todos.helpers({
  tasks: function () {
    return Tasks.find({});
   }
 });
}

works fine

Here's my meteor list

autopublish           1.0.4  (For prototyping only) Publish the entire database to all clients
blaze-html-templates  1.0.1  Compile HTML templates into reactive UI with Meteor Blaze
ecmascript            0.1.6* Compiler plugin that supports ES2015+ in all .js files
es5-shim              4.1.14  Shims and polyfills to improve ECMAScript 5 support
insecure              1.0.4  (For prototyping only) Allow all database writes from the client
jquery                1.11.4  Manipulate the DOM using CSS selectors
meteor-base           1.0.1  Packages that every Meteor app needs
mobile-experience     1.0.1  Packages for a great mobile user experience
mongo                 1.1.3  Adaptor for using MongoDB and Minimongo over DDP
session               1.1.1  Session variable
standard-minifiers    1.0.2  Standard minifiers used with Meteor apps by default.
tracker               1.0.9  Dependency tracker to allow reactive callbacks

and meteor is 1.2.1

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the assist. I copy/paste this directly into my cloud 9 workspace and it doesn't work. There are also no errors. Can you try to create one and see if it works for you? Or I could grant you access to mine?
that's directly copy pasted from a working version on my system
Okay something must be wrong with the cloud 9 configuration then
I updated mine with my 'meteor list' results, which show packages and their versions. Check it against yours / do meteor update
Tried it and added autopublish which was missing but still no success. :-(
|
1

change

Template.body.helpers({
  task: function () {
    return Tasks.find({});
   }
 });

to

Template.body.helpers({
  tasks: function () {
    return Tasks.find({});
   }
 });

Just make "task" in the js file plural, so it returns an array that the each statement can run through.

3 Comments

Hi! I tried this but also did not work. Any other ideas?
Can you explain how it did not work? Did you receive a specific error in the console?
There are no errors. You can run it here ide.c9.io/hilldesigns/meteor by typing meteor --port $IP:$PORT in the terminal @terrafirma9
0

Do you have anything in the mongo database?

Try adding a task to the db and see if you get the page update.

use:

meteor mongo

db.tasks.insert({ text: "Hello world!", createdAt: new Date() });

1 Comment

Which database? Meteor or local? I have documents in both and I still don't see anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.