Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2630

query filter on datetime field with lambda expression gives System.InvalidOperationException: {document..} is not supported

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.8.0
    • Component/s: Builders, Linq
    • None
    • Environment:
      Windows server 2012, visual studio, C# mongodb .net driver

      Could you please assist to get query working for below criteria ? 

       

      var filter3 = Builders<documentType>.Filter.Gt(f => f.usehour, 0)
      & Builders<documentType>.Filter.Ne("ExpirationDate", BsonNull.Value)
      & Builders<documentType>.Filter.Gt(f => f.ExpirationDate, DateTime.Now)
      & Builders<documentType>.Filter.Where(f => f.ExpirationDate.AddHours(f.usehour) > DateTime.Now )

      //& Builders<documentType>.Filter.Gt(f => f.ExpirationDate.AddHours(f.usehour) , DateTime.Now);  // tried this also

       

      Exception details:

      {document}{ExpirationDate}.AddHours(Convert({document}{usehour}, Double)) is not supported.


      {System.InvalidOperationException: {document} {ExpirationDate}

      .AddHours(Convert({document}

      {usehour}

      , Double)) is not supported.
      at MongoDB.Driver.Linq.Translators.PredicateTranslator.GetFieldExpression(Expression expression)
      at MongoDB.Driver.Linq.Translators.PredicateTranslator.TranslateComparison(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)
      at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node)
      at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
      at MongoDB.Driver.AndFilterDefinition`1.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
      at MongoDB.Driver.OrFilterDefinition`1.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
      at MongoDB.Driver.AndFilterDefinition`1.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
      at MongoDB.Driver.MongoCollectionImpl`1.CreateFindOperation[TProjection](FilterDefinition`1 filter, FindOptions`2 options)
      at MongoDB.Driver.MongoCollectionImpl`1.FindSync[TProjection](IClientSessionHandle session, FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)
      at MongoDB.Driver.MongoCollectionImpl`1.<>c_DisplayClass41_0`1.<FindSync>b_0(IClientSessionHandle session)
      at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)
      at MongoDB.Driver.MongoCollectionImpl`1.FindSync[TProjection](FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)
      at MongoDB.Driver.FindFluent`2.ToCursor(CancellationToken cancellationToken)
      at MongoDB.Driver.IAsyncCursorSourceExtensions.ToList[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)

       

       

       

            Assignee:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Reporter:
            poonam494 Poonam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: