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

only fields are allowed in a $sort when ordering by a nullable field

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.9.1
    • Component/s: None
    • Labels:
      None
    • Environment:
      Azure cloud (Windows)

      I am using OData against the MongoDB IQueryable collection and it works fine but when I try to sort by a nullable field it breaks with: only fields are allowed in a $sort when ordering by a nullable field

      If I convert that field to not nullable it works fine.

       
      api/TimeTracking/ItemType?$orderBy=ModifiedAt => error when nullable
      api/TimeTracking/ItemType?$orderBy=ModifiedAt => working when not nullable

      IMongoQueryable<T> query = queryOptions == null? entities.AsQueryable() : queryOptions.ApplyTo(entities.AsQueryable()) as IMongoQueryable<T>;
       

      Error:

      Exceptions.ErrorHandlingMiddleware:Error: Only fields are allowed in a $sort.
      
      System.NotSupportedException: Only fields are allowed in a $sort.
         at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateOrderBy(OrderByExpression node)
         at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslatePipeline(PipelineExpression node)
         at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry, ExpressionTranslationOptions translationOptions)
         at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
         at MongoDB.Driver.Linq.MongoQueryableImpl`2.ToCursorAsync(CancellationToken cancellationToken)
         at MongoDB.Driver.IAsyncCursorSourceExtensions.ToListAsync[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
      

      {{}}

      Did anyone have a similar experience? Is there a workaround for this?

      {{}}

      Nuget:

      {{}}

      • Microsoft.AspNetCore.OData v:7.1.0
      • MongoDB.Driver v:2.9.1

      {{}}

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            zolgera81@gmail.com Andrej Zolger
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: