[CSHARP-3940] Support BsonDocument and BsonArray in LINQ queries. Created: 28/Oct/21  Updated: 28/Oct/23  Resolved: 09/Nov/21

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

Type: Bug Priority: Major - P3
Reporter: James Kovacs Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Given a Collection<BsonDocument>, LINQ3 queries using doc["FieldName"] syntax fail with the following exception:

Unhandled Exception: MongoDB.Driver.Linq.Linq3Implementation.ExpressionNotSupportedException: Expression not supported: doc.get_Item("FieldName").
 

The same query works in LINQ2 using doc["FieldName"] or in LINQ3 with a POCO using doc.FieldName.

Full repro:

using System;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
 
var settings = new MongoClientSettings { LinqProvider = LinqProvider.V3 };
var client = new MongoClient(settings);
var db = client.GetDatabase("test");
var coll = db.GetCollection<BsonDocument>("coll");
 
var query = coll.AsQueryable().Where(doc => doc["createdAt"] == DateTime.Now);
foreach (var doc in query.ToList())
{
    Console.WriteLine(doc);
}



 Comments   
Comment by Githook User [ 09/Nov/21 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-3940: Support BsonDocument and BsonArray in LINQ queries.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/ccb46b7d446b6b5f3c11e24499d1a0a8a6b25380

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