2015-10-17 60 views
0

我想在流星集合中找到()。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); 
}); 

回答

0

啊哈原來我是個白癡,我已經刪除的包自動發佈。所以

$meteor add autopublish 

然後重新啓動應用程序修復它。