I can’t get a global variable for a week, which I will then need to change and compare with the text input area (I need a balance that compares with the rate and always changes when I win or lose) value, but does not want to 2, writes can not read property started):

code start:

Meteor.startup(() => { var oneUser = Animals.find({},{limit:1}).fetch()[0]; console.log(oneUser); userAnimals = oneUser.started; console.log(userAnimals); return 0; }); Template.hello.helpers({ counter() { var oneUser = Animals.find({},{limit:1}).fetch()[0]; console.log(oneUser); if(oneUser){ userAnimals = oneUser.started; console.log(userAnimals); } return 0; } }); 

Here is a shot

 undefined main.js:12 undefined main.js:12 Uncaught TypeError: Cannot read property 'started' of undefined at main.js:12 at maybeReady (meteor.js?hash=33066830ab46d87e2b249d2780805545e40ce9ba:927) at HTMLDocument.loadingCompleted (meteor.js?hash=33066830ab46d87e2b249d2780805545e40ce9ba:939) (anonymous) @ main.js:12 maybeReady @ meteor.js?hash=33066830ab46d87e2b249d2780805545e40ce9ba:927 loadingCompleted @ meteor.js?hash=33066830ab46d87e2b249d2780805545e40ce9ba:939 main.js:21 {_id: ObjectID, firsname: "Barsik", lastname: "Reshetnik", started: "122"} main.js:21 122 
  • most likely something is wrong with requests in Mongo. - Sonic Myst
  • instead of querying the database, enter some value / object and you should have no errors, check. - Sonic Myst
  • and by the way can not read the property started for the reason that oneUser = undefined, and undefined does not have the property started. - Sonic Myst
  • But it is there, why are there identical requests in one, but not in another? Why does it give an empty cursor 1 time, and when everything is done in the helper everything works? Why do I need to enter the value \ object if I need the value from the base (that is, the user's balance) - Lane
  • undefined is not an empty cursor, it is not a cursor at all. - Sonic Myst

1 answer 1

  1. Use the Session Persistent package

  2.  Meteor.publish("myGlobalAnimal", function(){ return Animal.findOne({}); }); 

But you will need to subscribe on the client side of Meteor.subscribe()

  1. Through the method you get

    Meteor.methods ({'getMyGlobalAnimal': function () {return myAnimal;}});