Created
July 27, 2017 13:15
-
-
Save ultimateprogramer/7936dae3e4b1d375b7babb638ab47821 to your computer and use it in GitHub Desktop.
MongoDB SSIS Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Download the MongoDB C# Drivers from https://docs.mongodb.com/ecosystem/drivers/csharp/ | |
| // Add the references to your project. | |
| // Create a Script Task. Now in the script, expand the Namespaces region and add these lines: | |
| using MongoDB.Bson; | |
| using MongoDB.Driver; | |
| using MongoDB.Bson.Serialization; | |
| // Now scroll down to the CreateNewOutputRows() procedure. Here is a sample of the code I used: | |
| public override void CreateNewOutputRows() | |
| { | |
| string connectionString = "mongodb://localhost"; | |
| string databaseName = "AdventureWorksDW2014"; | |
| var client = new MongoClient(connectionString); | |
| var server = client.GetServer(); | |
| var database = server.GetDatabase(databaseName); | |
| string CurrencyKey = ""; | |
| foreach (BsonDocument document in database.GetCollection<BsonDocument>("dbo.DimCurrency").FindAll()) | |
| { | |
| MongoDBDimCurrencyBuffer.AddRow(); | |
| MongoDBDimCurrencyBuffer.CurrencyName = document["CurrencyName"] == null ? "" : document["CurrencyName"].ToString(); | |
| MongoDBDimCurrencyBuffer.CurrencyAlternateKey = document["CurrencyAlternateKey"] == null ? "" : document["CurrencyAlternateKey"].ToString(); | |
| CurrencyKey = document["CurrencyKey"] == null ? "" : document["CurrencyKey"].ToString(); | |
| MongoDBDimCurrencyBuffer.CurrencyKey = Convert.ToInt32(CurrencyKey); | |
| MongoDBDimCurrencyBuffer.ID = document["_id"] == null ? "" : document["_id"].ToString(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment