我正在尝试通过 C# 驱动程序对子集合进行建模,但我发现这样做很困难;你能帮我做这件事吗,或者一些完整的例子吗?
我正在努力实现这一目标;
{
id:"id", name: 'name', Tokens:[{name:"yes",expiry:'Today'}, {name:"Hello", expiry:"tomorow"}]
}
我已经为这样的课程建模
Class sample
{
[BSON]
public string id{get; set;}
public string name{get; set;}
public TokensCollection[] tokens(get; set;}
}
public class TokensCollection
{
public string name{get;set;}
public string expiry{get;set;}
}
在存储库中,我试图像这样初始化它,
Sample sample1 = new Sample{
id = ObjectId.GenerateNewId().ToString();
name = "name";
//Best way to model this? any pointers?
for (int index =1; index <=2; index++)
{
tokens[index].name = "me";
tokens[index].expiry = "Today"
}
collection.insert(sample1);
有人可以帮我解决这个问题吗?