title: Combining $regex and $or operators in Mongo
body: <p>I want to use <code>$or</code> and <code>$regex</code> operators same time.</p>
  
  <blockquote>
    <p><code>db.users.insert([{name: "Alice"}, {name: "Bob"}, {name: "Carol"}, {name: "Dan"}, {name: "Dave"}])</code></p>
  </blockquote>
  
  <p>Using <code>$regex</code> works fine:</p>
  
  <pre><code>&gt; db.users.find({name: {$regex: "^Da"}})
  { "_id" : ObjectId("53e33682b09f1ca437078b1d"), "name" : "Dan" }
  { "_id" : ObjectId("53e33682b09f1ca437078b1e"), "name" : "Dave" }
  </code></pre>
  
  <p>When introducing <code>$or</code>, the response is changed. I expected the same response:</p>
  
  <pre><code>&gt; db.users.find({name: {$regex: {$or: ["^Da"]}}})
  { "_id" : ObjectId("53e33682b09f1ca437078b1a"), "name" : "Alice" }
  { "_id" : ObjectId("53e33682b09f1ca437078b1b"), "name" : "Bob" }
  { "_id" : ObjectId("53e33682b09f1ca437078b1c"), "name" : "Carol" }
  { "_id" : ObjectId("53e33682b09f1ca437078b1d"), "name" : "Dan" }
  { "_id" : ObjectId("53e33682b09f1ca437078b1e"), "name" : "Dave" }
  </code></pre>
  
  <p>I also tried to change the order of the operators:</p>
  
  <pre><code>&gt; db.users.find({name: {$or: [{$regex: "^Da"}, {$regex: "^Ali"}]}})
  error: { "$err" : "invalid operator: $or", "code" : 10068 }
  </code></pre>
  
  <p>However, it seems that following query works fine, but it's a little bit long (<code>name</code> is repeated):</p>
  
  <pre><code>&gt; db.users.find({$or: [{name: {$regex: "^Da"}}, {name: {$regex: "^Ali"}}]})
  { "_id" : ObjectId("53e33682b09f1ca437078b1a"), "name" : "Alice" }
  { "_id" : ObjectId("53e33682b09f1ca437078b1d"), "name" : "Dan" }
  { "_id" : ObjectId("53e33682b09f1ca437078b1e"), "name" : "Dave" }
  </code></pre>
  
  <p>Is there any shorter way to use <code>$regex</code> and <code>$or</code> in queries like this?</p>
  
  <p>The goal is to use <code>$regex</code> operator and not <code>/.../</code> (real regular expressions).</p>