Tested using version 2.7.3 of the C# driver.
Issue appears to be in MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate.
Given the following document:
{ "_id" : ObjectId("5c5c8d915018e66f49cf8b59"), "UserAttributes" : { "CustomerClass" : "Schools", "CustomerSubClass" : "Law Schools" }, "UserId" : "urn:idprofile:PA10000" }
this code will fail:
public class User { public ObjectId _id; public string UserId { get; set; } public Dictionary<string, string> UserAttributes = new Dictionary<string, string>(); } var uri = "xxx"; var mongoURL = new MongoUrl(uri); var client = new MongoClient(mongoURL); var database = client.GetDatabase("csharp"); var Users = database.GetCollection<User>("Users"); int count = Users.AsQueryable().Where(x => x.UserAttributes.ContainsValue("Law Schools")).Count();
The error that is produced:
System.ArgumentException HResult=0x80070057 Message=Unsupported filter: \{document}{UserAttributes}.ContainsValue("Law Schools"). Source=MongoDB.Driver StackTrace: at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node) at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry) at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateWhere(WhereExpression node) at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node) at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateGroupBy(GroupByExpression node) at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node) at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslatePipeline(PipelineExpression node) at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node) at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry, ExpressionTranslationOptions translationOptions) at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Translate(Expression expression) at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute(Expression expression) at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute[TResult](Expression expression) at System.Linq.Queryable.Count[TSource](IQueryable`1 source) at ConsoleApp1.Program.Test2() in C:\Workspace\ConsoleApp1\ConsoleApp1\Program.cs:line 77 at ConsoleApp1.Program.Main(String[] args) in C:\Workspace\ConsoleApp1\ConsoleApp1\Program.cs:line 31
- mentioned in
-
Page Loading...