I have an object that looks like this:
var searchFilter = {_id: XXX, approved: true}
Which is used to drive a Meteor collection search filter. I then have a pair of text boxes that allow the user to enter in a range of dates, in which case I update the filter to trigger Meteor to reactively re-run the filter, like so:
// Some Meteor event-handler...
var val = // code to pull val in...not important...
var searchFilter = Session.get('searchFilter');
if (!val || val === '') {
delete searchFilter.created_on;
} else {
searchFilter.created_on = {$gte: new Date(val)};
}
Session.set('searchFilter', searchFilter);
The else that removes the create_on child object works great for one field, but in my code I have two fields, one for a beginning range and one for an ending range. What I need to be able to do is remove the created_on: {$gte}, then check if created_on is "empty", and if so, remove the whole thing. I am not sure how I go about doing that, though. Is this possible? I have access to jQuery and underscore.js as libraries, if that helps.