I am using the Official MongoDB C# Drive v0.9.1.26831, but I was wondering given a POCO class, is there anyway to ignore certain properties from getting inserted.
For ex
Just in case somebody might be interested in another way of doing it. Via conventions:
public class IgnoreSomePropertyConvention : ConventionBase, IMemberMapConvention
{
public void Apply(BsonMemberMap memberMap)
{ // more checks will go here for the case above, e.g. type check
if (memberMap.MemberName != "DoNotWantToSaveThis")
memberMap.SetShouldSerializeMethod(o => false);
}
}
And then you need to register this convention once during you app startup:
ConventionRegistry.Register("MyConventions", new ConventionPack { new IgnoreBaseIdConvention() }, t => true);