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); }