2016-04-15 19 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

相关问题