[英]Query to return in BSON document from an embedded collection in MongoDB using C#
I have an embedded collection in MongoDB like this : 我在MongoDB中有一个嵌入式集合,像这样:
{
"Earth":
{
"Asia":
{
"India":
{
"Capital" : "New Delhi",
"Language " :"Hindi"
},
"Japan":
{
"Capital":"Tokyo",
"Language": "Japanese"
},
"China":
{
"Capital":"Beijing",
"Language": "Chinese"
}
}
}
}
The country name is given as user input & I've to display that country information, for eg:, if the input given is India, the output should be : 国家名称作为用户输入给出,我必须显示该国家信息,例如:如果输入的是印度,则输出应为:
{
"capital": "New Delhi",
"language", "Hindi"
}
How to retrieve this from MongoDB to a BSON document using C#? 如何使用C#从MongoDB检索到BSON文档?
Maybe consider this: 也许考虑一下:
internal class Country
{
public string Continent { get; set; }
public string Capital { get; set; }
public string Language { get; set; }
}
Create your Countries and put them in a list: 创建您的国家并将其放在列表中:
private static IEnumerable<BsonDocument> CreateCountries()
{
var India = new BsonDocument
{
{"Continent", "Asia"},
{"Capital", "New Delhi"},
{"Language", "Hindi"}
};
var Japan = new BsonDocument
{
{"Continent", "Asia"},
{"Capital", "Tokyo"},
{"Language", "Japanese"}
};
var China = new BsonDocument
{
{"Continent", "Asia"},
{"Capital", "Beijing"},
{"Language", "Chinese"}
};
var newEarth = new List<BsonDocument>();
newEarth.Add(India);
newEarth.Add(Japan);
newEarth.Add(China);
return newEarth;
}
}
This way you can accept input for India search the List and return any information associated with India. 这样,您可以接受印度的输入,以搜索列表并返回与印度相关的任何信息。 For more help with this you can go HERE
如需更多帮助,请点击这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.