我想将一个子文档添加到现有文档的列表中。该文件是这样的:在MongoDB中添加一个新的子文档
public class EtaMembershipDocument : DocumentBase
{
public List<EtaAssociationDocument> EtaAssociatonDocuments { get; set; }
}
我在茫然,如何将新EtaAssociationDocument
添加到使用C#和MongoDB列表。这是我最新的尝试:
var collection = this.DataStore.GetCollection<EtaMembershipDocument>(EtaMembershipsCollectionName);
Update.AddToSet("EtaAssociationDocuments", BsonValue.Create(etaAssociationDocument));
在最后一行,我得到这个错误:
.NET type EtaAssociationDocument cannot be mapped to a BsonValue.
的问题是,我甚至不知道这是不是我应该如何添加首先是一个子文档。如果我的方法是正确的,我能做些什么来解决错误?如果我的方法不正确,我该怎么做?
[BsonValue和MongoDB C#驱动程序中的自定义类的可能的重复](http://stackoverflow.com/questions/7732663/bsonvalue-and-custom-classes-in-mongodb-c-sharp-driver) –