[CSHARP-4737] Linq3Implementation: MongoDB.Driver.Linq.ExpressionNotSupportedException Created: 01/Aug/23 Updated: 27/Oct/23 Resolved: 27/Oct/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Builders |
| Affects Version/s: | 2.20.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Blocker - P1 |
| Reporter: | Sasan Pasha | Assignee: | Robert Stam |
| Resolution: | Won't Fix | Votes: | 1 |
| Labels: | Bug | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
| Description |
SummaryWhen i use update multiple fields, and the fields are multiple arrays, I get ExpressionNotSupportedException MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: b.Contributors.FirstMatchingElement().TransactionDetails.FirstOrDefault(t => (t.TransactionId == "b2231207-ad5c-4236-8517-5fdc5e7c5139")).
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).How to ReproduceSteps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example. var builder = Builders<Funding>.Filter; var result = await FundingsCollection.UpdateOneAsync(filter, update);
Additional BackgroundPlease provide any additional background information that may be helpful in diagnosing the bug. |
| Comments |
| Comment by Robert Stam [ 27/Oct/23 ] |
|
Closing for now as we have no plans at the moment to address this particular unusual edge case. The root of the problem is that there is no equivalent MQL that the expression can be translated to. Some users have commented that using array filters instead might work, but I have not attempted to verify that. |
| Comment by Shiya Kohn [ 24/Aug/23 ] |
|
Hi sasan.pasha@gmail.com , there is no support for Linq and arrayFilters, and from my pedestrian review of the source code, there isn't really an easy path towards it. I think for now you have to use raw MQL for it |
| Comment by Sasan Pasha [ 24/Aug/23 ] |
|
hi skohn@goflow.com - I think arrayFilters is the way to go forward. however, there is not a good documentation on using c#, Linq and arrayfilters |
| Comment by Shiya Kohn [ 24/Aug/23 ] |
|
If you can think of some way to translate this to MQL that I am overlooking please let me know. I don't think there's any easy way to do this in code, but what if it were able to become an arrayFilters? As far as locally modifying the document and doing a replace, that can be risky and introduce race conditions. |
| Comment by Sasan Pasha [ 08/Aug/23 ] |
|
thanks for the clarification - this is not effective coding. what about using array filters? |
| Comment by Robert Stam [ 08/Aug/23 ] |
|
Thanks for reporting it even if it turns out that it can't be supported. It's always worth investigating. There are limits to the kind of logic you can apply in an update command. Those limits are determined by what is possible to express in MQL. You always have the option of fetching the entire document client side and modifying it locally (using the full power of C#), and then writing the document back to the server. The possible downside to this approach is that if the document is very large you are transferring a lot of data back and forth over the network. |
| Comment by Sasan Pasha [ 07/Aug/23 ] |
|
hi robert@mongodb.com I don't have the expertise on the matter - I reported the issue since LINQ3 is not working for the query. Is there any alternative to run the above query with success? Or perhaps the community can translate that to MQL. |
| Comment by Robert Stam [ 07/Aug/23 ] |
|
I don't think it is possible to translate this UpdateDefinition to MQL. There isn't any MQL that it can be translated to. The issue is that the following expression needs to be translatable to a field name, but it is not possible: b.Contributors.FirstMatchingElement().TransactionDetails.FirstOrDefault(t => t.TransactionId == receiver.FromTransactionId) If you can think of some way to translate this to MQL that I am overlooking please let me know. |
| Comment by PM Bot [ 01/Aug/23 ] |
|
Hi sasan.pasha@gmail.com, thank you for reporting this issue! The team will look into it and get back to you soon. |