2016-04-15 49 views
0

我試圖訪問存儲在集合中的userIds,然後使用它們來發布所有meteor.users的詳細信息。我的發佈功能不是不返回任何東西?使用不同集合中的ID發佈用戶

Meteor.publish('allUsersWithOffers', function() { 
    var user = Offers.find({}, {fields: {"UserId": 1}}); 

    return Meteor.users.find({_id: user}); 

}); 

回答

1

試試這個:

Meteor.publish('allUsersWithOffers', function() { 
    var offers = Offers.find({}, { fields: { UserId: 1 } }).fetch(); 
    var ids = _.pluck(offers, 'UserId'); 

    // This is critical - you must limit the fields returned from 
    // the users collection! Update this as needed. 
    options = { fields: { username: 1, emails: 1 } }; 
    return Meteor.users.find({ _id: { $in: ids } }, options); 
}); 

find返回遊標 - 你需要調用fetch實際得到的文件。

+0

不錯。我建議閱讀我的[常見錯誤](https://dweldon.silvrback.com/common-mistakes)文章 - 它解決了這裏遇到的幾個問題。 –

+0

我會檢查出來。 – bp123

相關問題