Baku Retsu
Baku Retsu

Reputation: 61

Unable to to query Dictionary item using MongoDB C# 2.0 Drivers

I have a class that has a dictionary property in it.

    [DataMember]
    [BsonElement("QueriableParameters")]
    public Dictionary<string, string> QueriableParameters
    {
        get;
        set;
    }

I'm using the new MongoDB c# 2.0 drivers and can't seem to be able to do this:

var selectQuery1 = await collection.Find(s => s.QueriableParameters["UniqueLoanNumber"] == "3049793b-91eb-49d8-a5b4-7cbfd1a1bb3c").ToListAsync();

I get this error stating that:

InnerException: System.InvalidOperationException
   HResult=-2146233079
   Message=s.QueriableParameters.get_Item("UniqueLoanNumber") is not supported.
   Source=MongoDB.Driver
   StackTrace:
        at MongoDB.Driver.Linq.Translators.PredicateTranslator.GetSerializationInfo(Expression expression)
        at MongoDB.Driver.Linq.Translators.PredicateTranslator.BuildComparisonQuery(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)

Please help point me in the right direction.

Thanks,

Upvotes: 3

Views: 2610

Answers (3)

Ankit Arya
Ankit Arya

Reputation: 51

This issue is resolved in the latest Mongo C# driver version i.e 2.2.3. Link: https://github.com/mongodb/mongo-csharp-driver

Upvotes: 0

Baku Retsu
Baku Retsu

Reputation: 61

Thank you Craig for the information.

I guess the only way to do it right now is to :

var builders = Builders<NotificationData>.Filter;
var filter = builders.Eq("QueriableParameters.UniqueLoanNumber", "theIdLookingfor");
var selectQuery = await collection.Find(filter).ToListAsync();

Upvotes: 3

Craig Wilson
Craig Wilson

Reputation: 12624

This is currently not possible. This ticket has already been filed related to this: https://jira.mongodb.org/browse/CSHARP-917.

Craig

Upvotes: 0

Related Questions