2017-08-31 52 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; 
    } 
}); 

,然後我訂閱的項目上的客戶端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

你可以添加代碼你publi使用'Meteor.publish()'集合sh? –

+1

確保'schema'和'publication'文件正確導入到服務器的'main.js' –

回答

0

我沒有」 t發佈....

Meteor.publish('tasks', function() { 
    return Tasks.find(); 
}); 
相關問題