title: Construct a selector with if statements in JavaScript
body: <p>I create a MongoDB selector from some session variables. If the session value is null, the selector should not include the condition.</p>
  
  <p>I have a selector</p>
  
  <pre><code>return Session.get('title') ? { title: Session.get('title') } : {};
  </code></pre>
  
  <p>which works as it should; however, I want to filter on more session values.</p>
  
  <p>If I add another one, I get</p>
  
  <pre><code>var title = Session.get('title');
  var age = Session.get('age');
  
  if (title &amp;&amp; age) {
    return {
      title: title,
      age: age
    };
  } else if (title) {
    return {
      title: title
    };
  } else if (age) {
    return {
      age: age
    }
  } else {
    return {}
  }
  </code></pre>
  
  <p>and it will only get more complicated when I add another session value.</p>
  
  <p>How can I obtain the same result in a smarter way?</p>