-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Unknown
-
None
-
Affects Version/s: 2.20.0
-
Component/s: None
-
None
Summary
After upgrading the MongoDB C# driver from 2.15.0 to 2.20.0, I am getting ExpressionNotSupportedException for one of my queries. I am running MongoDB 5.0.18.
How to Reproduce
I have the following object:
public class UnlockableModel { [BsonId] public Guid profileId { get; set; } public Dictionary<String, List<String>> entries { get; set; } }
The following query will fail with ExpressionNotSupportedException:
List<string> categories = new List<string> {"Test"}; var filter = Builders<UnlockableModel>.Filter.Eq(model => model.profileId, profileId); var options = new FindOptions<UnlockableModel> { Projection = Builders<UnlockableModel>.Projection.Expression(p => new UnlockableModel { profileId = p.profileId, entries = (p.entries != null) ? new(p.entries.Where(kvp => categories.Contains(kvp.Key))) : new() }) }; var result = await _unlockableCollection.FindAsync(filter, options);
Downgrading the connection to LinqProvider.V2 fixes the issue:
var connectionString = "mongodb://localhost"; MongoClientSettings settings = MongoClientSettings.FromConnectionString(connectionString); settings.LinqProvider = LinqProvider.V2;
- duplicates
-
CSHARP-4763 Consider supporting client side projections with Find and Select in LINQ3
- Closed
- related to
-
CSHARP-4779 Support Dictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection) constructor in LINQ3
- Backlog