1 / 1
Jan 31

Hi, I’m trying to do a very simple thing, I want to flatten a document to a class like so:

Document:

{ code: "123", data: { other_code: "456", } }

Class:

public class MyClass { [BsonElement("code")] public String Code { get; set; } [BsonElement("data.other_code")] public String OtherCode { get; set; } }

And then I want to be able to use it in a typed query like so:

va filter = Builders<MyClass>.Filter.Where(x => x.OtherCode == "456")

The filter generated does uses my string with dot notation:

"data.other_code" : "456"

But when I execute the query with:

List<Myclass> results = collection.Find(filter ).ToList();

The member OtherCode is not populated and stays NULL. Any thoughts on how I could do it ?

I tried to write a custom BsonSerializer but the Deserialize method is never called.

Thanks for your help !