title: Moongose MongoDB: LIKE operator in search
body: <p>After read some solutions to use "LIKE" in Mongoose:</p>
  
  <p><a href="https://stackoverflow.com/questions/9824010/mongoose-js-find-user-by-username-like-value">Mongoose.js: Find user by username LIKE value</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3305561/how-to-query-mongodb-with-like">How to query MongoDB with &quot;like&quot;?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/11362113/mongodb-dynamic-like-operator">Mongodb dynamic like operator</a></p>
  
  <p>I'm using this code to simulate "SQL LIKE" in Mongoose:</p>
  
  <p><strong>Find: <em>'joseph'</em>   -->  Result:  <em>Josephine Doyle</em></strong></p>
  
  <pre><code>var word = 'joseph';
  
  User
      .find({name: new RegExp(word, 'i')})
      .sort('-created')
      .exec(function(err, users){
          if (err) {
              console.log(err);
              return res.status(400).send({
                  message: errorHandler.getErrorMessage(err)
              });
          } else {
              res.jsonp(users);
          }
      });
  </code></pre>
  
  <p>The result of this is the user Josephine Doyle, OK.</p>
  
  <p>Now I want to use the same code, but with this word to search: </p>
  
  <p><strong>Find: <em>'josephine do'</em>   -->  Result:  <em>Josephine Doyle</em></strong></p>
  
  <pre><code>var word = 'josephine do';
  </code></pre>
  
  <p>OK, works too...</p>
  
  <p><strong>More examples than works:</strong></p>
  
  <ul>
  <li><p>Find: <em>'josephine doyle'</em>   -->  Result:  <em>Josephine Doyle</em></p></li>
  <li><p>Find: <em>'jos doyle'</em>   -->  Result:  <em>Josephine Doyle</em></p></li>
  </ul>
  
  <p><strong>But, I want to solve this case of problems:</strong></p>
  
  <ul>
  <li>Find: <em>'doyle josephine'</em>   -->  Result:  <em>{}</em> </li>
  <li>Find: <em>'do josephine'</em>   -->  Result:  <em>{}</em> </li>
  <li><p>Find: <em>'doyle jo'</em>   -->  Result:  <em>{}</em> </p>
  
  <p><strong><em>(Different order words doesn't work)</em></strong></p></li>
  <li><p>Find: 'josephine</p>
  
  <p>doyle'   -->  Result:  <em>{}</em> </p>
  
  <p><strong><em>(With more than one space between words doesn't work)</em></strong></p></li>
  </ul>
  
  <p>Any suggestions? Maybe another RegEx? Thanks!</p>