Reputation: 3417
I'm trying to publish a list of users. I'm checking a collection for accoutActive: true
and then fetching the studentUserId
. I thought I could then use this to find the meteor.user however it returns nothing. Could someone please tell me what I'm missing.
Meteor.publish('list', function() {
var activeStudent = StudentAccountStatus.find(
{"accountActive": true},
{fields:
{"studentUserId": 1}
}
).fetch();
return Meteor.users.find(
{_id: activeStudent}
);
});
Upvotes: 0
Views: 31
Reputation: 661
Currently your activeStudent variable contains an array of objects which would look something like this:
[ { _id: 'a104259adsjf' },
{ _id: 'eawor7u98faj' },
... ]
whereas for your mongo query you just need an array of strings, i.e. ['a104259adsjf', 'eawor7u98faj', ...]
.
So, you need to iterate through your array of objects to construct the array of strings, like with the lodash _.map function:
var activeStudentIds = _.map(activeStudent, function(obj) {
return obj._id;
});
Then, using the mongo $in selector you can reformulate your query as:
return Meteor.users.find(
{_id: { $in: activeStudentIds } }
);
Upvotes: 1