MongoDB からデータを取得するスクリプトを SSIS で作成しました。通常のドキュメントのクエリに問題はありませんが、ネストされたドキュメントから値を取得する方法がわかりません。たとえば、展開された「住所」には、「国」、「都道府県」、「市区町村」、「番地」、および「郵便番号」が含まれます。「国」(フィールド)の値のみを取得することに興味があります。理論的には、「Address.Country」のようなものにする必要があることは理解していますが、コードに実装する方法がわかりません。それを達成するための最良の方法は何ですか?
これは、他のすべてのドキュメントを取得するコードです。
public override void CreateNewOutputRows()
{
string connectionString = "mongodb://localhost";
MongoServer myMongo = MongoServer.Create(connectionString);
myMongo.Connect();
var db = myMongo.GetDatabase("UserDB");
/*ICursor<BsonDocument> cursor = db.GetCollection<BsonDocument>("UserDB").FindAll();*/
foreach (BsonDocument document in db.GetCollection<BsonDocument>("UserDB").FindAll())
{
this.UserDBBuffer.AddRow();
this.UserDBBuffer.ID = document["_id"] == null ? "" : document["_id"].ToString();
this.UserDBBuffer.PrimaryEmail = document["primary_email"] == null ? "" : document["primary_email"].ToString();
this.UserDBBuffer.Gender = document["gender"] == null ? "" : document["gender"].ToString();
}
}