[CSHARP-4723] Linq V2 Projection when upgrading from 2.19.1 to 2.19.2 Created: 14/Jul/23  Updated: 28/Oct/23  Resolved: 02/Aug/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.19.2
Fix Version/s: 2.21.0

Type: Bug Priority: Unknown
Reporter: Fred Morel Assignee: Oleksandr Poliakov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on CSHARP-4742 Find and Aggregate Project should wor... Closed
Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

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?


 Description   

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...



 Comments   
Comment by Githook User [ 02/Aug/23 ]

Author:

{'name': 'Oleksandr Poliakov', 'email': '31327136+sanych-sun@users.noreply.github.com', 'username': 'sanych-sun'}

Message: CSHARP-4723: Linq V2 Projection when upgrading from 2.19.1 to 2.19.2 (#1144)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/945ae832d56f59bb68cc1c91292f6031b36fec30

Comment by Robert Stam [ 02/Aug/23 ]

This ticket is partially about x => x projection and partially about FindOneAndReplace calling Render instead of RenderForFind.

The x => x part has been factored out as CSHARP-4742.

Comment by Robert Stam [ 24/Jul/23 ]

oleksandr.poliakov@mongodb.com can you look at 4681 at the same time? I think they are related.

Update: I misread the projection as x => x (instead of x => x.Id). Perhaps this is not actually related to 4681.

Comment by Boris Dogadov [ 17/Jul/23 ]

Thanks you for filling this bug fred.morel@onepeloton.com .
We have reproduced the issue.

Please follow this ticket for any further updates.

Comment by PM Bot [ 14/Jul/23 ]

Hi fred.morel@onepeloton.com, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Wed Feb 07 21:49:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.