Almog
Almog

Reputation: 2837

Meteor find on an array

I'm trying iterate on an array and return my collection

I have the following

Meteor.publish('collaborators', function() {
  var topics = Topics.findOne({$or:[{
    userId: this.userId,
  }, {
    collaboratorsIds: this.userId,
  }, {
    inviteeId:this.userId,
  }]});

  return Collaborators.find({
    topicId: topics._id,
  });
}); 

topics is an array and I would like the Collaborators.find to iterate and return

Upvotes: 0

Views: 259

Answers (1)

Hubert OG
Hubert OG

Reputation: 19544

You can use the $in operator to include all elements of an array of _ids:

return Collaborators.find({
  topicId: {$in: _.pluck(topics, '_id')},
});

Upvotes: 1

Related Questions