2016-05-24 18 views
0

此Meteor客戶端代碼預計會返回一個在服務器控制檯上正常工作的文檔。 db.validationCol.findOne({'key':'myname'}); 集合findOne正在返回undefiend

但是在客戶端返回undefiend。它如何被修復?由於

// server 
ValidationCol = new Mongo.Collection('validationCol'); 

Meteor.publish('validationCol', function() { 
    return ValidationCol.find({}); 
}); 

(function() { 
    const docs = { 
    myname: '^[0-9a-zA-Z]{65}$' 
    }; 
    for (let property in docs) { 
    if (docs.hasOwnProperty(property)) { 
     ValidationCol.insert({key: property, regex: docs[property]}); 
    } 
    } 
})(); 

//client 
let key = 'myname' 
     let regex = ValidationCol.findOne({key: key}); 
     console.log(regex); 

回答

0

你有你的客戶端代碼中訂閱:

ValidationCol = new Mongo.Collection('validationCol'); 

Meteor.publish('validationCol', function() { 
    return ValidationCol.find({}); 
}); 

(function() { 
    const docs = { 
    myname: '^[0-9a-zA-Z]{65}$' 
    }; 
    for (let property in docs) { 
    if (docs.hasOwnProperty(property)) { 
     ValidationCol.insert({key: property, regex: docs[property]}); 
    } 
    } 
})(); 

//client 
let key = 'myname' 
// Subscription 
Meteor.subscribe('validationCol'); 
let regex = ValidationCol.findOne({key: key}); 
console.log(regex);