Simple Todos tutorial gives no Tasks from MongoDB


#1

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.


#2

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


#3

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") }

#4

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.


#5

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


#6

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,


#7

same problem goes here!! any one please help


#8

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:


#9

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


#10

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


#11

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