Modelling SubCollections

84 views
Skip to the first unread message

Vishnu

unread,
13 Oct 2012, 06:20:0313/10/2012
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,
16 Oct 2012, 16:41:5916/10/2012
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,
18 Oct 2012, 03:15:4018/10/2012
to mongodb...@googlegroups.com
This is awesome.

Thank you very much. :)

V
Reply all
Reply to author
Forward
0 new messages