title: MongoDB C# driver, query by an array element using regex
body: <p>I am using MongoDB C# driver <strong>version 2.2</strong>. My collection contains "Parent" objects. Each parent object has an array of children objects. Each child has name value:</p>
  
  <pre><code>"parent": {
      "children":[
          { "name": "Bob", "age": 10},
          { "name": "Alice", "age": 7},
          { "name": "Tobias", "age": 11}
      ]
  }
  </code></pre>
  
  <p>I need to translate the following code into C# statements / LINQ syntax:</p>
  
  <pre><code>db.getCollection('Parents').find({'parent.children': { $elemMatch: { 'name': { $regex: '.*ob.*', $options: 'im' } }}})
  </code></pre>
  
  <p>I have found there are methods like</p>
  
  <pre><code>var builder = Builders&lt;BsonDocument&gt;.Filter;
  builder.Regex("parent.children.name", new BsonRegularExpression(".*ob.*")); //does not work with array
  </code></pre>
  
  <p>and</p>
  
  <pre><code>builder.AnyEq("parent.children.name", "ob"); //without regex
  </code></pre>
  
  <p>But I cannot understand how to combine them. Please advise.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I am using the following for now, please correct me if you know a reason why it should not work correctly:</p>
  
  <pre><code>builder.AnyEq("parent.children.name", new BsonRegularExpression(".*ob.*"))
  </code></pre>