我有一个mongo集合:Scaffold
。如果嵌入对象BooksStream
,Fieldset
具有列表。
Fieldset
有一个Field
,我想对这本字典的价值有所了解。
Field
这是我要输入的值的示例。某种键值集合 :
保存时,这是我在mongo中拥有的值 。
答案 0 :(得分:0)
嗯。它像应该工作的那样工作>
static void Main(string[] args)
{
var client = new MongoClient();
var database = client.GetDatabase("SO3");
var collection = database.GetCollection<Fieldset>("jobject");
var id = new BsonObjectId(ObjectId.GenerateNewId()).ToString();
var field =
new Field
{
Config = new Dictionary<string, object> {{"value", "item1key"}, {"lable", "item1value"}}
};
var field2 =
new Field
{
Config = new Dictionary<string, object> {{"value", "item2key"}, {"lable", "item2value"}}
};
var fieldset = new Fieldset
{
Id = id,
Slug = "aa",
Fields = new List<Field>
{
field,
field2
}
};
collection.InsertOne(fieldset);
}
{ "_id" : ObjectId("5c55b972ceb9443d385de936"), "Slug" : "aa", "Fields" : [ { "Config" : { "value" : "item1key", "lable" : "item1value" } }, { "Config" : { "value" : "item2key", "lable" : "item2value" } } ] }