我試圖通過C#驅動程序建模子集合,但我發現很難這樣做;你能幫我做些什麼嗎?或者有一些完整的例子可以用來做同樣的事情嗎?在c中建模mongodb子集合#
我試圖達到這個目標;
{
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);
有人能幫助我嗎?
是的,你做到了.. :) –