I created a script in SSIS to retrieve data from MongoDB. While I don't have any issues querying regular documents, I am not sure how to retrieve values from nested documents. For example, "Address" expanded contains "Country", "State", "City", "Street", and "Zip". I am interested in retrieving the "Country" (field) values only. In theory, I understand that it should be something like "Address.Country", but I do not know how to implement it in my code. What is the best way to achieve that?
This is the code that retrieves all the other documents:
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();
}
}