添加BSON阵列BsonDocument在MongoDB中 [英] Adding BSON array to BsonDocument in MongoDB
本文介绍了添加BSON阵列BsonDocument在MongoDB中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何在MongoDB中使用C#驱动程序添加到BsonArray BsonDocument?我想结果是这样的。
{
作者:'乔',
标题:然而,另一篇博客',
文字:这里是文本...',
标签:例如','乔'],
注释:[{笔者:吉姆 ,评论:我不同意'},
{笔者:南希,评论:好职位}
]
}
解决方案
您可以创建在C#中使用以下语句上述文件:
VAR文件=新BsonDocument {
{作者,乔},
{称号,又一个博客文章},
{文本,这里是文本...},
{标签,新BsonArray {榜样,乔}},
{意见 ,新BsonArray {
新BsonDocument {{作者,吉姆},{评论,我不同意}},
新BsonDocument {{作者,南希}, {评论,好职位}}
}
};
您可以测试是否有与写结果:
VAR JSON = document.ToJson();
How can I add BsonArray to BsonDocument in MongoDB using a C# driver? I want a result something like this
{
author: 'joe',
title : 'Yet another blog post',
text : 'Here is the text...',
tags : [ 'example', 'joe' ],
comments : [ { author: 'jim', comment: 'I disagree' },
{ author: 'nancy', comment: 'Good post' }
]
}
解决方案
You can create the above document in C# with the following statement:
var document = new BsonDocument {
{ "author", "joe" },
{ "title", "yet another blog post" },
{ "text", "here is the text..." },
{ "tags", new BsonArray { "example", "joe" } },
{ "comments", new BsonArray {
new BsonDocument { { "author", "jim" }, { "comment", "I disagree" } },
new BsonDocument { { "author", "nancy" }, { "comment", "Good post" } }
}}
};
You can test whether you got the write result with:
var json = document.ToJson();
这篇关于添加BSON阵列BsonDocument在MongoDB中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文