I'm currently displaying ALL users from Meteor.users.find() on a webpage with {{#each user}}. However, I want to limit my search based on zip codes.
- User enters zip code.
- Find city name of zip code.
- Find all zip codes within that city.
- Find all users having ANY of the zip codes in that city.
List all users on page.
// Step 1: User input (OK) input_zip = '1234'; // Step 2: Get city name for this ZIP (OK) var zip_place = Locations.findOne({ zipCode: input_zip })['place']; // Step 3: Get all zip codes in that city (OK) var zip_codes = Locations.find({ place: zip_place }).fetch(); // Step 4 (I'm aware this syntax is totally wrong, but you get the idea) var zip_users = Meteor.users.find({ profile.zipcode: zip_codes }).fetch(); // Step 5: List users on page with zip codes in that array. {{#each user in zip_users}} <p>bla bla</p> {{/each}}
What is the most effective way of searching for users with values from an array? Complete code example will be much appreciated. Thank you.