[CSHARP-4627] Support Union via $unionWith in LINQ3 Created: 25/Apr/23  Updated: 28/Oct/23  Resolved: 11/May/23

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

Type: New Feature Priority: Unknown
Reporter: James Kovacs Assignee: Oleksandr Poliakov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CSHARP-4623 Linq Union Not Working 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   

Repro with 2.19.1:

using MongoDB.Bson;
using MongoDB.Driver;
 
var client = new MongoClient();
var db = client.GetDatabase("test");
var coll1 = db.GetCollection<BsonDocument>("coll1");
var coll2 = db.GetCollection<BsonDocument>("coll2");
 
var query = coll1.AsQueryable().Union(coll2.AsQueryable());
 
var results = query.ToList();

Output:

Unhandled exception. MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: test.coll1.Aggregate([]).Union(test.coll2.Aggregate([])).
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.ExpressionToPipelineTranslator.Translate(TranslationContext context, Expression expression)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.Translate[TDocument,TOutput](MongoQueryProvider`1 provider, Expression expression)
   at MongoDB.Driver.Linq.Linq3Implementation.MongoQuery`2.Execute()
   at MongoDB.Driver.Linq.Linq3Implementation.MongoQuery`2.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Program.<Main>$(String[] args) in /Users/james/Dropbox/code/cases/csharp4627/Program.cs:line 11



 Comments   
Comment by Githook User [ 18/May/23 ]

Author:

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

Message: CSHARP-4627: Ignore UnionWith tests on servers prior to 4.4 (#1082)
Branch: v2.19.x
https://github.com/mongodb/mongo-csharp-driver/commit/08b69476f38352cbc8bda3a9d9d38339d1311d56

Comment by Githook User [ 18/May/23 ]

Author:

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

Message: CSHARP-4627: Support Union via $unionWith in LINQ3 (#1078)
Branch: v2.19.x
https://github.com/mongodb/mongo-csharp-driver/commit/c9e1e28b1c7bdecf5d844e9269e95f5e124c1935

Comment by Githook User [ 11/May/23 ]

Author:

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

Message: CSHARP-4627: Ignore UnionWith tests on servers prior to 4.4 (#1082)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/e97ce5ecb5ffb3b806e4af9808aca80b2183d6ea

Comment by Githook User [ 11/May/23 ]

Author:

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

Message: CSHARP-4627: Support Union via $unionWith in LINQ3 (#1078)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/4af549c37621582f221e66edd561b679384c6396

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