title: How to create query that searches for field equals string or int
body: <p>I have a mongodb collection where the userId field is sometimes an int and sometimes a string. (55 or "55")</p>
  
  <p>Using the .NET driver, I create query parts based on a <code>MongoDBLogEntry</code> class:</p>
  
  <pre><code>var filters = new List&lt;FilterDefinition&lt;MongoDBLogEntry&gt;&gt;();
  foreach (var docFilter in docFilters)
  {
      var key = docFilter.Key; // Example: "userId"
      var value = docFilter.Value;  // Example: "55"
  
      FilterDefinition&lt;MongoDBLogEntry&gt; filter;
      if (key.EndsWith("Id"))
      {
          var intfilter = builder.Eq(key, BsonInt32.Create(Convert.ToInt32(value)));
          var stringFilter = builder.Eq(key, value);
          var orFilter = builder.Or(intfilter, stringFilter);
          filter = orFilter;
      }
      else
      {
          filter = builder.Eq(docFilter.Key, value);
      }
  
      filters.Add(filter);
  }
  </code></pre>
  
  <p>Because my data has string or int for some fields, my <code>MongoDBLogEntry</code> class defines userId field as a string, with a <code>StringOrIntSerializer : SerializerBase&lt;string&gt;</code> serializer on those fields.</p>
  
  <p>My issue is that the query that is created for one of the id fields is:</p>
  
  <pre><code>{ "$or" : [{ "userId" : "55" }, { "userId" : "55" }] }
  </code></pre>
  
  <p>I've also tried an <code>$in</code> clause, that that also ends up being two string values, <code>"55", "55"</code></p>
  
  <p>I <em>think</em> I understand why those are being converted to strings... because my <code>MongoDBLogEntry</code> class defines the field that way and converts all values to a string.</p>
  
  <p><strong>But is there a way for me to force an <code>int</code> into the query with the code above?</strong></p>