CONTEXT
I am trying to create a search functionality allowing users to fill in multiple fields, submit, and see a list of matching items from one collection. I do this using a form on the front end, which updates session variables on back-end, which are then passed as query to a mongodb collection.
HOW IT SHOULD WORK
If a user submits a venue size, then venues of that size are shown. If only a location is typed in, then venues within that location are shown. If both a size and a location are submitted, then venues that match both criteria are shown.
HOW IT ACTUALLY WORKS
If nothing is filled in, pressing search yields all items in the collection. Submitting both location and size yields venues that match both criteria. However, filling in only one field and leaving the other empty yields nothing in results. I'm wondering why this might be - it's almost as if the query is searching for a field that literally contains ''... but then why don't I see this behavior when leaving both fields empty? Help much appreciated!
CODE SNIPPET
//Search Form Helper
Template.managevenues.helpers({
venue: function () {
var venueNameVar = Session.get('venueNameVar');
var venueLocationVar = Session.get('venueLocationVar');
if(venueNameVar || venueLocationVar){
console.log(venueNameVar);
console.log(venueLocationVar);
return Venues.find({
venueName: venueNameVar,
'venueAddress.neighbourhood': venueLocationVar
});
} else {
return Venues.find({});
}
});