title: Get records by collection datetime property & complexity comperansion
body: <p>I have a model with startDate and endDate Property.
  When inserting the model to mongo, the datetime is translated to ISO format datetime string.
  I am trying to get document by dates range properties using LINQ on collection as documented at mongodb documentation <em><a href="https://mongodb-documentation.readthedocs.io/en/latest/ecosystem/tutorial/use-linq-queries-with-csharp-driver.html#gsc.tab=0" rel="nofollow noreferrer">https://mongodb-documentation.readthedocs.io/en/latest/ecosystem/tutorial/use-linq-queries-with-csharp-driver.html#gsc.tab=0</a></em></p>
  <p>My C# code model relevant props:</p>
  <pre><code>public DateTime StartWorkDate { get; set; }
  public DateTime FinishWorkDate { get; set; }
  </code></pre>
  <p>mongodb document relevant props:
  <a href="https://i.stack.imgur.com/Mxuiw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mxuiw.png" alt="enter image description here" /></a></p>
  <p>My code where i try to get document by dates range</p>
  <pre><code>GetRecordsByDate(DateTime start,DateTime end){
  ...
  var collection = _db.GetCollection&lt;TestModel&gt;(&quot;TestCollection&quot;);
  var query = from test in collection.AsQueryable&lt;TestModel&gt;()
              where (DateTime.Compare(test.StartWorkDate, start) &gt; 0 || DateTime.Compare(test.StartWorkDate, start) == 0) &amp;&amp;
                          (DateTime.Compare(test.FinishWorkDate, end) &lt; 0 || DateTime.Compare(test.FinishWorkDate, end) == 0)
                          select test;
            
  return query.ToList();
  }
  </code></pre>
  <p>I get the following exception:
  Message:<code>System.InvalidOperationException: 'Compare({document}{StartWorkDate}, 01/01/2019 00:00:00) is not supported</code></p>
  <p>If i try get all documents and then run the same query on the result it works perfect:</p>
  <pre><code>GetRecordsByDate(DateTime start,DateTime end){
  ...
  var collection = _db.GetCollection&lt;TestModel&gt;(&quot;TestCollection&quot;);
  var resTemp = collection.Find(Builders&lt;TestModel&gt;.Filter.Empty).ToList();
  
  var collectionResult = resTemp.Where(test =&gt;
                   (DateTime.Compare(test.StartWorkDate, start) &gt; 0 || DateTime.Compare(test.StartWorkDate, start) == 0) &amp;&amp;
                   (DateTime.Compare(test.FinishWorkDate, end) &lt; 0 || DateTime.Compare(test.FinishWorkDate, end) == 0)
                   ).ToList();
  
  }
  </code></pre>
  <p>Which brings me to my other question (its just a good to know question):
  I know its better using query on the mongo because its querying system is very efficient, But what is the difference between running the query on mongo then getting all documents and then running linq on them as i did at my working code</p>