2013-10-29 97 views
0

我在MongoDB的一個集合用戶提供了這樣每個用戶一個小部件文檔訪問子文檔:MongoDB中

Widgets = [{ 
type: 'container', 
size: 12, 
offset: 0, 
id: 'root', 
children: [ 
    { 
     type: 'widgetSearch', 
     title: 'Recherche', 
     offset: 0, 
     size: 2, 
     id: 'searchId', 
     toolbar: { 
      buttons: [ 'config', 'move', 'minimize', 'maximize', 'close' ] 
     } 
    },...etc 

在文件client.js我想在窗口小部件的數據訪問。

我試試這個:

var user = Meteor.user(); 
var test = Meteor.users.find({_id: user._id}); 

console.log(test.widgets); 

console.log(test[0].widgets); 

我在做什麼錯在這裏?

+0

如果子文檔被稱爲Widgets(大寫W),您可能希望將'test.Widgets'用於訪問子文檔 – tim

回答

2

流星默認情況下不會發布用戶帳戶的自定義字段。您需要自行發佈每個用戶所需的字段。

Meteor.publish(null, function() { 
    return Meteor.users.find({_id: this.userId}, {fields: {widgets: 1, profile: 1, etc: 1 }}); 
});