流星收集findOne回调undefined时调用回调

问题描述:

我想在流星集合中找到()。fetch(),但是当我在回调中调用此代码(或直接在控制台中,它返回[ ])。流星收集findOne回调undefined时调用回调

MyClass = class MyClass { 
    constructor() { 
     this.worker = null; 
     this._init(); 

     console.log(Site.MyCollection.find().fetch()); //Logs the array of documents 
    } 

    _init() { 
     this.worker = new Worker('my-web-worker.js'); 
     this.worker.addEventListener('message', this._onMessage, false); 

     this.worker.postMessage({ cmd: 'start', data: Site.MyCollection.find().fetch() }); //Works fine, the Web Worker receives the array of documents as expected 

    } 


    _onMessage(e) { 
     console.log(Site.MyCollection.find().fetch()); //Logs [] 
    } 
} 

没有任何地方,我从集合中移除任何文件,所以我不能确定这是否是一个安全功能,或者以某种方式集合创建后擦拭。

要创建(虚拟)集合,我这样做(在客户端和服务器上)

Site.MyCollection = new Mongo.Collection("my-collection"); 

Site.MyCollection.remove(); 

let docs = [ 
    {name:"One", data : ["a", "b", "c"}}, 
    {name:"Two", data : ["e", "f", "g"}}, 
    {name:"Three", data : ["h", "i", "j"}}, 
    {name:"Four", data : ["k", "l", "m"}} 
]; 

_.each(docs, function(doc){ 
    Site.MyCollection.insert(doc); 
}); 

啊哈原来我是个白痴,我已经删除的包自动发布。所以

$meteor add autopublish 

然后重新启动应用程序修复它。