Reputation: 416
I'm looking to implement a search/filter function. It will use a drop down bar as its inputs (so we the user chooses from a set of options).
How my system works now is this: There is a Meteor.users collection, and an Instruments collection. Basically, each user has a list of instruments he plays (for example, Bob plays piano and violin, Alice plays the piano and the flute). In this case, there are 4 objects in the Instruments collection:
1) type: Piano owner: (bob's ID)
2) type: Violin owner: (bob's ID)
3) type: Piano owner: (Alice's ID)
4) type: Flute owner: (Alice's ID)
So what I'm trying to do is, when I choose "piano" on my drop down list, and then click search, I want it to display Bob and Alice's profiles. I guess this should be done using Meteor's publish feature, but just not sure how to do it (I'm a beginner here).
For example, if how do I tell that specific publication to run when I hit search? I see examples of people setting publish rules to only publish the subset they are searching for, but how do we tell it when to happen? Do we use another template for that so that when we click "search", the URL path changes and thus a different template?
To be clear, my question is just how should I go about doing this. Thanks!
Upvotes: 0
Views: 346
Reputation: 565
To make it easy, try to bind the instrument ID in Person's Collection as Array,
[{
_id: 'BoBId',
Instrumets: [PianoId, ViolinId],
},{
_id: 'AliceId',
Instrumets: [PianoId, ViolinId],
}];
now you could find any profile, who has the instruments
Person.find({
Instruments:{
$in:[InstrumentsId]
}
});
Upvotes: 2