ElemMatch を使用して、2.2 ドライバーを使用して MongoDB でドキュメントを検索しようとしていますが、成功しません。次のような例外が発生します。
System.InvalidOperationException : フィールド 'EnabledForProduct' のシリアライザーは、IBsonArraySerializer を実装し、アイテムのシリアル化情報を提供する必要があります。
私のクラスは次のようになります。
public class Document
{
public string Id {get; set;}
public Dictionary<Product, bool> EnabledForProduct { get; set; }
}
public enum Product {Product1,Product2};
私の ClassMap は次のようになります。
BsonClassMap.RegisterClassMap<Document>(cm =>
{
cm.AutoMap();
cm.MapMember(c => c.EnabledForProduct)
.SetSerializer(new DictionaryInterfaceImplementerSerializer<Dictionary<Product, bool>>(DictionaryRepresentation.ArrayOfDocuments,
BsonSerializer.LookupSerializer<int>(),
BsonSerializer.LookupSerializer<bool>()));
});
次のようなフィルターを使用しようとすると、例外が発生します。
Builders<Document>.Filter.ElemMatch(f => f.EnabledForProduct,
x => x.Key == Product1 && x.Value))
これは、1.x ドライバーで問題なく動作していました。
私が間違っていることを誰かが知っていますか?