我在SSIS中创建了一个脚本,从MongoDB中检索数据。虽然我没有任何查询常规文档的问题,但我不知道如何从嵌套的文档中检索值。例如,“Address”展开包含“Country”,“State”,“City”,“Street”和“Zip”。我只想检索“Country”(字段)值。理论上,我知道它应该是像“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();
}
}