2017-08-31 10 views
0

私はたくさんのタスクを作成する関数を作成し、それらをサーバー関数にすべて出力し、サーバーログに表示します。コンソールでTasks.find()。fetch()を実行すると、空の配列が返されます。私はここで間違って何をしていますか?コンソールに同じように設定されて表示されるようないくつかのオブジェクトがあります。アプリのルートのオフ 'のコレクション' フォルダにコレクションはコンソールでは空白として表示されますが、Meteorサーバーでは表示されるのはなぜですか?

let createDummyTasks = function(){ 
    var numberToFake=1000; 
    var equipment = ["Auto Folding Machine", "Binding Machine", 
        "Scissor Machine", "Folding Machine", 
        "Cutting Machine"]; 
    for (let i = 0; i < numberToFake; i++) { 
     createDummyTask(); 
    } 
    console.log(Tasks.find().fetch()) 

    function createDummyTask(){ 
     let name = faker.name.jobArea(); 
     let status = randomStatus(); 
     let duration = Math.floor(Math.random() * 40) + 1;  
     let startDate = faker.date.between('2017-09-10', '2017-09-17'); 
     let endDate = faker.date.between('2017-09-18', '2017-09-30'); 
     let equipment = Equipment.aggregate({$sample: {size: 1}}); 
     // let thisEquipment = equipment[Math.floor(Math.random() * equipment.length)] 

     Tasks.insert({name: name, 
        status: status, 
        duration: duration, 
        startDate: startDate, 
        endDate: endDate 
        }, function(error){ 
         if(error){ 
          console.log("error"); 
         } else { 
          console.log("success"); 
         } 
        }) 

    } 

} 

私が持っているtask.js

Tasks = new Mongo.Collection('tasks'); 

Tasks.allow({ 
    insert() { 
    // When we will ALLOW inserts on the client. 
    return false; 
    }, 
    update() { 
    // When we will ALLOW updates on the client. 
    return false; 
    }, 
    remove() { 
    // When we will ALLOW removes on the client. 
    return false; 
    } 
}); 

Tasks.deny({ 
    insert() { 
    // When we will DENY inserts on the client. 
    return true; 
    }, 
    update() { 
    // When we will DENY updates on the client. 
    return true; 
    }, 
    remove() { 
    // When we will DENY removes on the client. 
    return true; 
    } 
}); 

、その後、私はdidnのクライアントJS

// ************************************************************* 
Template.schedule.onCreated(() => { 
    Template.instance().subscribe('customers'); 
    Template.instance().subscribe('jobs'); 
    Template.instance().subscribe('tasks'); 
    Template.instance().subscribe('equipment'); 

}); 

Template.widget.onRendered(function(){ 
    if(Meteor.isDevelopment){ 
     Meteor.call('populateDummyInfo', (error)=>{ 
      if(error){ 
       console.log(error); 
      } 
     }) 
    } 
}) 
+1

公開するコードを追加することはできますか'Meteor.publish()'でコレクションをshしますか? –

+1

'schema'ファイルと' publication'ファイルがサーバーの 'main.js'に適切にインポートされていることを確認してください –

答えて

0

上のアイテムをサブスクライブ」公開する....

Meteor.publish('tasks', function() { 
    return Tasks.find(); 
}); 
関連する問題