MongoDB ignore property on serialization but not on deserialization

Viewed 100

I am new to MongoDB and trying to do One-to-Many Relationships with Document References. I'm getting the exception “Element does not match any field or property of class” when use $lookup to join the company collection. I guess the company field will be ignored on deserialization as well. Is there a way to achieve this?

public class Company
{
    [BsonId]
    [BsonRepresentation(BsonType.ObjectId)]
    public string id { get; set; }
    public string abn { get; set; }
    public string businessName { get; set; }
}

public class Shop
{
    [BsonId]
    [BsonRepresentation(BsonType.ObjectId)]
    public string id { get; set; }
    [BsonRepresentation(BsonType.ObjectId)]
    public string company_id { get; set; }
    [BsonIgnore]
    public Company company { get; set; }
    public string name { get; set; }
    public string shortName { get; set; }
    ...
}

0 Answers
Related