Reputation: 2589
I defined a Collection in the model.js like this:
People = new Meteor.Collection("people");
Here's the code in main.js:
function test2(){
console.log(JSON.stringify(People.find().fetch()));
setTimeout(test2,5000)
}
if (Meteor.isServer) {
if(People.find().fetch().length === 0){
var tom = {name:"Tom",age:18};
People.insert(tom);
}
Meteor.startup(function () {
test2();
});
}
Here are the errors I get:
I want to Meteor execute some CRUD on the Collection automatically at set intervals. So I'm using setTimeOut
, but it seems to be difficult.
Any idea about what I am doing wrong?
Upvotes: 1
Views: 2609
Reputation: 75955
Use Meteor.setTimeout instead:
Meteor.setTimeout(test2,5000)
On the server meteor code is run using fibers to let your write synchronous code, javascript's timeout has to let its callback fire in a fiber too, especially if it contains meteor code.
Upvotes: 5