Meteor.Collection issue - templates dont receive data

Hey guys!

I’m just following the Pluralsight Tutorial for Meteor.js.
I came across the part where you can create a Collection/MongoDB to persist “users”.
That all is pretty cool - but the issue here for me is that it is not working. I followed the video exactly but it still did not work.

ProteinTracker.js => http://pastebin.com/aHq7kfbu
ProteinTracker.html => http://pastebin.com/smLpTnpS

Please point out what I am doing wrong here!

Thanks for your help

Charlie

Template.userHistory.helpers({
  historyItem() {
    return [
      {date : '12/24/2016 0200', value : 40},
      {date : '12/24/2016 0300', value : 32},
      {date : '12/24/2016 0400', value : 23},
      {date : '12/24/2016 0500', value : 412},
      {date : '12/24/2016 0600', value : 41}
    ]
  }
});

Note: I used ES2015 syntax. If you prefer ES5:

Template.userHistory.helpers({
  historyItem: function() {
    return [
      {date : '12/24/2016 0200', value : 40},
      {date : '12/24/2016 0300', value : 32},
      {date : '12/24/2016 0400', value : 23},
      {date : '12/24/2016 0500', value : 412},
      {date : '12/24/2016 0600', value : 41}
    ]
  }
});

Edit: Just a small suggestion that you edit this topic title: you aren’t using a collection for your historyItem helper, so you don’t actually have a Meteor.Collection issue.

Also, regarding your code (I assume from the tutorial): Meteor.Collection was deprecated over a year ago. You should be using Mongo.Collection.

hey there!

Well I’ll stick to JS Style because I’m working with JS all the time tho - thanks for the suggestion tho.

About “userHistory” - actually I wanted to point out:

Template.userDetails.helpers({ user: function(){ return Users.findOne(); }

userHistory does work fine.

the userDetails Template population.

About that Meteor.Collection is deprecated I gonna take a look if that may help!

EDIT: Sadly the Mongo.Collection did not changed a thing :confused:

Well I tried to figure out what happens but since I’m new to Meteor.js I dont have a real clue.

Some notes:

When calling an “insert” to Mongo everything works fine. “Users” has “Users.find().count() === 0”.
After inserting the count() === 1. So far so good. All works fine that way.

The snippet:
Users = new Meteor.Collection('users'); Users.insert({ total : 120, goal : 200 });

but - actually I want it to happen on the serverside (like in the pluralsight course). Therefore I need to check if the Users Collection is empty and if yes then I need to insert a document.

The snippes:
`if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup

if (Users.find().count() === 0) {
  Users.insert({
    total : 120,
    goal : 200
  });
}

});
}`

This is even weirder. Because when I console.log the actual Users.find().count() to that moment (to get sure my expression will be true) it says “5”. And after I tested things with the above code (inserting users document right after Users = new Meteor.Collection(‘user’)) it says “6”.

I heared that there are two replicas of a mongo instance. One on Clientside and one on the server side. My suggestion is that I constantly raising the serverside MongoDB so the expression for the insert does not work.
BUT
if so - the Users Collection should have documents in it. But they dont appear to be accessable on the clientside at the moment the template is about to get populated.

So what do I need to synchronize the clientside db with the serverside one soon enough so they share the same state?

thanks for your help!

I fixed the problem. It was because I had many “test inserts” the firstOne() found was pretty messed up so it couldnt be viewed properbly. After doing “meteor reset” I was able to reset the DB and therefore try with the new clean database entries.