Hello all
I'm trying to model subcollections through C# driver, but I'm finding it difficult to do so; could you some help me to do it or some full fledged example for the same please?
I'm trying to acheive this;
{
id:"id", name: 'name', Tokens:[{name:"yes",expiry:'Today'}, {name:"Hello", expiry:"tomorow"}]
}
I have modelled a class like this
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;}
}
And in the repository I'm trying to initialize the same like this,
Sample sample1 = new Sample{
id = ObjectId.GenerateNewId().ToString();
name = "name";
for (int index =1; index <=2; index++)
{
tokens[index].name = "me";
tokens[index].expiry = "Today"
}
collection.insert(sample1);
Could someone help me with this please?
V