Make sure you register the new convention package early enough. If any classes have already been mapped before you register a new agreement package, they will not be updated.
Here is my test code:
public class C { public int Id { get; set; } public string S { get; set; } } public static class Program { public static void Main(string[] args) { ConventionRegistry.Register( "Ignore null values", new ConventionPack { new IgnoreIfNullConvention(true) }, t => true); var client = new MongoClient("mongodb://localhost"); var server = client.GetServer(); var database = server.GetDatabase("test"); var collection = database.GetCollection<C>("test"); collection.Drop(); collection.Insert(new C { Id = 1, S = null }); Console.WriteLine("Press Enter to continue."); Console.ReadLine(); } }
The following document has been inserted into the database:
db.test.find ()
{ "_id" : 1 }
Source: https://groups.google.com/forum/#!topic/mongodb-user/7-NFXBNeEXs
source share