Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Problem after upgrading latest version of MongoDB .NET driver

Hi Team,

I am facing issue with my existing query after i upgraded to mongodb driver 2.10.3 from 1.9, the query which i am facing issue given below

IQueryable query = mongoDatabase.GetCollection(“MonitorProfileDB”).AsQueryable().
Where(a => a.MonitorUser.GetType() == typeof(DefaultMonitorUserInfo));
MongoDB Driver 1.9 :- query sending to mongdb server like below

{{ “MonitorUser._t.0” : { “$exists” : false }, “MonitorUser._t” : “DefaultMonitorUserInfo” }}

MongoDB Driver 2.10.3 :- query sending to mongodb server like below

{{ “MonitorUser._t.0” : { “$exists” : false }, “MonitorUser._t” : “MongoDriver1._9.DefaultMonitorUserInfo, MongoDriver1.9” }}

Note :- because of the _t value sending full assembly name data not filtering properly.

Kindly please help me to resolve this issue.

Hi @Devaraj_S, welcome!

The _t value is related to the discriminator used in polymorphism. This would depends on how your class definition is written.

It would be useful for others, if you would provide a minimal reproducible code that others could try to reproduce the issue between the two versions of the driver.

Regards,
Wan.

Hi Wan,

Thanks for the reply, here i given the elements which you requested,

My Document entity structure :-

public class Entity
{
[BsonElement("Property1 ")]
public IInterface Property1 { get; set; }
}

public interface IInterface 
{

}

[BsonDiscriminator("ClassA")]
public class ClassA: IInterface
{
    [BsonElement("Property1")]
    public Int64 Property1{ get; set; }

    [BsonElement("Property2")]
    public Int64 Property2{ get; set; }
}

Sample Document :-

{
“_id” : ObjectId(“5bf8c6ca234d5f26944727fd”),
“_t” : “Entity”,
“Property1” : {
“_t” : “ClassA”,
“Property1” : NumberLong(0),
“Property2” : NumberLong(10004)
}
}

Failed Query in the new .Net mongodb driver 2.10.3 :-

IQueryable query = mongoDatabase.GetCollection(“EntityCollection”).AsQueryable().
Where(a => a.Property1.GetType() == typeof(ClassA));

MongoDB Driver 1.9 :- query sending to mongdb server like below

{{ “Property1._t.0” : { “$exists” : false }, “Property1._t” : “ClassA” }}

MongoDB Driver 2.10.3 :- query sending to mongodb server like below

{{ “Property1._t.0” : { “$exists” : false }, “Property1._t” : “Folder1.Folder2.ClassA, NameSpace” }}

I hope given details what you have requested, could you please let me know if there are any queries or details if you required.

Hi Team,

Is there anything i can do for the above problem which i am facing right now for the mongoDB driver upgrade.