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

Linq V2 Projection when upgrading from 2.19.1 to 2.19.2

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.21.0
    • Affects Version/s: 2.19.2
    • Component/s: None
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      A LINQ projection that used to work is now failing. Specifically, `x => x`.

      We have helper method to wrap most FindOneAndUpdates to consistently handles things like "ID does not exist". To reduce code, there's an overload with no projection that just calls the overload that supports projection with a barebones `x => x`.

      After upgrading to 2.19.2, this is now throwing an exception. We are still using the V2 LINQ translator.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      When upgrading driver from 2.19.1 to 2.19.2.

      MongoDB 6.0.x running in Atlas.

      How to Reproduce

      Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

      var id = ObjectId.GenerateNewId();
      var update = Builders<TDocument>.Update.Set("example", 2);
      var options = new FindOneAndUpdateOptions<TDocument>()
      {
          Projection = Builders<TDocument>.Projection.Expression(x => x),
      };
      collection.FindOneAndUpdate<TDocument, TDocument>(x => x.Id == id, update, options); 

      Additional Background

      Stack trace:

       System.NotSupportedException : $project or $group does not support {document}.
      Stack Trace:
      41     at MongoDB.Driver.Linq.Linq2Implementation.Translators.AggregateLanguageTranslator.TranslateValue(Expression node)
      42   at MongoDB.Driver.Linq.Linq2Implementation.Translators.AggregateLanguageTranslator.Translate(Expression node, ExpressionTranslationOptions translationOptions)
      43   at MongoDB.Driver.Linq.Linq2Implementation.Translators.AggregateProjectTranslator.TranslateProject(Expression expression, ExpressionTranslationOptions translationOptions)
      44   at MongoDB.Driver.Linq.Linq2Implementation.Translators.AggregateProjectTranslator.Translate[TDocument,TResult](Expression`1 projector, IBsonSerializer`1 parameterSerializer, IBsonSerializerRegistry serializerRegistry, ExpressionTranslationOptions translationOptions)
      45   at MongoDB.Driver.Linq.Linq2Implementation.LinqProviderAdapterV2.TranslateExpressionToProjection[TInput,TOutput](Expression`1 expression, IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry, ExpressionTranslationOptions translationOptions)
      46   at MongoDB.Driver.ExpressionProjectionDefinition`2.Render(IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)
      47   at MongoDB.Driver.MongoCollectionImpl`1.CreateFindOneAndUpdateOperation[TProjection](FilterDefinition`1 filter, UpdateDefinition`1 update, FindOneAndUpdateOptions`2 options)
      48   at MongoDB.Driver.MongoCollectionImpl`1.FindOneAndUpdateAsync[TProjection](IClientSessionHandle session, FilterDefinition`1 filter, UpdateDefinition`1 update, FindOneAndUpdateOptions`2 options, CancellationToken cancellationToken)
      49   at MongoDB.Driver.MongoCollectionImpl`1.<>c__DisplayClass60_0`1.<FindOneAndUpdateAsync>b__0(IClientSessionHandle session)
      50   at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
      ...my code...

            Assignee:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Reporter:
            fred.morel@onepeloton.com Fred Morel
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: