title: Using a regex with text search in MongoDB
body: <p>I have created a text index on the <code>num</code> field in the collection. Now while passing the string to search from the <em>text index</em>, I need to use a regex which has to be passed as a string to the <code>$search</code> variable.</p>
  <p>My current query works fine but it doesn't work when I add a regex to it.</p>
  <p>Current Query:</p>
  <pre><code>db.collection.find({$text:{$search:&quot;1234 6789&quot;}},{'id':1})
  </code></pre>
  <p>I need to add a regex/like query to the <code>$search</code> to make it something like</p>
  <pre><code>db.collection.find({$text:{$search:&quot;/1234/ /6789/&quot;}},{'id':1})
  </code></pre>
  <p>where I get all the values from the database that contain a pattern like &quot;1234&quot; OR &quot;6789&quot;.</p>
  <p>I did try the query but it gives me a <code>$search</code> needs a String error:</p>
  <pre><code>db.collection.find({$text:{$search:/1234/}},{'id':1})
  </code></pre>