title: MongoDB Closest Match on properties
body: <p>Let says I have a Users collection in MongoDB whose schema looks like this:</p>
  
  <pre><code>{
      name: String,
      sport: String,
      favoriteColor: String
  }
  </code></pre>
  
  <p>And lets say I passed in values like this to match a user on:</p>
  
  <p><code>{ name: "Thomas", sport: "Tennis", favoriteColor:"blue" }</code></p>
  
  <p>What I would like to do is match the user based off all those properties. However, if no user comes back, I would like to match a user on just these properties:</p>
  
  <p><code>{sport: "Tennis", favoriteColor:"blue" }</code></p>
  
  <p>And if no user comes back, I would like to match a user on just this property:</p>
  
  <p><code>{ favoriteColor: "blue" }</code></p>
  
  <p>Is it possible to do something like this in one query with Mongo? I saw the <code>$switch</code> condition in Mongo that will match on a case and then immediately return, but the problem is that I can't access the document it would have retrieved in the <code>then</code> block. It looks like you can only write strings in there.</p>
  
  <p>Any suggestions on how to accomplish what I'm looking for? </p>
  
  <p>Is the best thing (and only way) to just execute multiple <code>User.find({...})</code> queries?</p>