为什么集合在控制台中显示为空白,但在Meteor服务器中可用?

时间:2017-08-31 16:40:29

标签: mongodb meteor console

我创建了一个创建一大堆任务的函数,它将它们全部打印出服务器函数并显示在服务器日志中。当我在控制台中运行Tasks.find()。fetch()时,它返回一个空白数组。我在这做错了什么?我有一些其他对象似乎以相同的方式设置并且DO显示在控制台中。

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");
                        }
                    })

    }

}

收藏&#39;应用程序根目录下的文件夹我有一个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 个答案:

答案 0 :(得分:0)

我没有发表....

Meteor.publish('tasks', function () {
  return Tasks.find();
});