Skip to content

Instantly share code, notes, and snippets.

@ultimateprogramer
Created July 27, 2017 13:15
Show Gist options
  • Select an option

  • Save ultimateprogramer/7936dae3e4b1d375b7babb638ab47821 to your computer and use it in GitHub Desktop.

Select an option

Save ultimateprogramer/7936dae3e4b1d375b7babb638ab47821 to your computer and use it in GitHub Desktop.
MongoDB SSIS Integration
// 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