title: Mongoose: ignore parameter in query if it is null
body: <p>I have a simple REST API and I would like to implement filtering on a specific endpoint.</p>
  
  <p>Imagine I have an endpoint like this:</p>
  
  <pre><code>localhost:5000/api/items?color="red"
  </code></pre>
  
  <p>Which handles request like this:</p>
  
  <pre><code>const items = await Items.find({color: req.query.color})
  </code></pre>
  
  <p>This works when the <code>color</code> parameter is present. However, if the <code>color</code> parameter is omitted then the query searches for items where the <code>color</code> is <code>undefined</code>. This is not the behaviour I need.</p>
  
  <p>In my case, I would like to add <strong>multiple filter parameters</strong> which are ignored if they are not present. Do I have to create a separate query for each case or is there an option to tell Mongoose not to search for a field (in this case <code>color</code>) if it is null or undefined?</p>