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

関連する問題