My meteor directory is consists of 2 files:
social.js:
Messages = new Meteor.Collection("messages");
if (Meteor.isServer) {
}
if (Meteor.isClient) {
Template.temple.messages = function() {
return Messages.find();
};
Meteor.startup(function () {
console.log('console startup: ' + Messages.find().count());
});
console.log('console normal: ' + Messages.find().count());
var ali = function() {
console.log('console normal: ' + Messages.find().count());
};
setTimeout(function() {
console.log('console normal: ' + Messages.find().count());
}, 2000);
// The callback function is not called on the following line:
Meteor.subscribe('messages',function(){alert('ALERT!');});
}
social.html:
<head>
<title>naber</title>
</head>
<body>
{{> temple}}
</body>
<template name = "temple">
{{#each messages}}
{{message}} <br />
{{/each}}
</template>
The collection is fully loaded only after some time has passed. I can only see the true count of documents if I wrap around a setTimeout
. What can I do to ensure that my functions are executed after the database is truly and fully available?