Modelling SubCollections

85 views
Skip to first unread message

Vishnu

unread,
Oct 13, 2012, 6:20:03 AM10/13/12
to mongodb...@googlegroups.com
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

Bear

unread,
Oct 16, 2012, 4:41:59 PM10/16/12
to mongodb...@googlegroups.com
Hi Vishnu,

Using the latest version of the driver, try this example in a console app;
http://pastie.org/5069720

Thanks

Vishnu

unread,
Oct 18, 2012, 3:15:40 AM10/18/12
to mongodb...@googlegroups.com
This is awesome.

Thank you very much. :)

V
Reply all
Reply to author
Forward
0 new messages