Simple Todos tutorial gives no Tasks from MongoDB

Hi, I was following the tutorial Simple Todos and got stuck at the 3rd step:

https://www.meteor.com/tutorials/blaze/collections

I just get blank Todo list no matter how many items I populate into MongoDB using:

meteor mongo

I tried both on Mac & Linux and get the same issue. No error, no crash, just Tasks collection is empty. All I did is just copying from the tutorial:

tasks.js

import { Mongo } from 'meteor/mongo';
export const Tasks = new Mongo.Collection('tasks');

body.js

Template.body.helpers({
    tasks() {
        // Show newest tasks at the top
        return Tasks.find({}, { sort: { createdAt: -1 } });
    },
});

Installation details:

Meteor 1.3.2.4 has been installed in your home directory (~/.meteor).
Writing a launcher script to /usr/local/bin/meteor for your convenience.

Any help is appreciated. Thank you.

need a bit more info…can you check in your console if task items exist?
Tasks.find().fetch()

Sorry which console?

When I ran meteor mongo and db.tasks.find(), I get results:

{ "_id" : ObjectId("571ead1842d501eb9ed99f58"), "text" : "Feed the pets", "createdAt" : ISODate("2016-04-25T23:49:44.541Z") }

So I didn’t read the tutorial very carefully :slight_smile: I had to import tasks.js into server/main.js :slight_smile: Thanks for helping.

1 Like

ah i thought it had something to with import…trust me wont be the last time you forget to import something :smiley:

1 Like

Hey, I got very same problem, I cannot see data from db on my webpage. After reading this branch I doubled checked my imports and I got everything imported as mentioned in the tutorial. I am sure that I inserted data to database because I can see objects in my database using cmd.
I just started to learn how to use meteor and I get immediately stuck.
I appreciate any help,

same problem goes here!! any one please help

I fixed up my problem by writing code on server/main.js file like this i hope this works for you too

import { Meteor } from ‘meteor/meteor’;
import { Mongo} from ‘meteor/mongo’;

Meteor.startup(() => {
// code to run on server at startup
Tasks = new Mongo.Collection(‘tasks’);
});:grin:

2 Likes

Thank you very much for fast reply. It fixed my problem too.

This confused me too, but see https://github.com/meteor/tutorials/issues/30 -

The tasks.js import goes in server/main.js and not client/main.js

3 Likes

haha… same problem. note the difference between server/main.js and client/main.js

5 Likes

Maybe the tutorial styles must be updated a bit to make it more clear the file name/path is different. I spend some time searching what is the problem with my MongoDB. It’s a bit frustrating to fail a tutorial on the second step.

Hello World - Jan 2019 :slight_smile: