<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MongoDB Archives | ZappySys Blog</title>
	<atom:link href="https://zappysys.com/blog/tag/mongodb/feed/" rel="self" type="application/rss+xml" />
	<link>https://zappysys.com/blog/tag/mongodb/</link>
	<description>SSIS / ODBC Drivers / API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more</description>
	<lastBuildDate>Thu, 11 Dec 2025 12:38:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.4</generator>

<image>
	<url>https://zappysys.com/blog/wp-content/uploads/2023/01/cropped-zappysys-symbol-large-32x32.png</url>
	<title>MongoDB Archives | ZappySys Blog</title>
	<link>https://zappysys.com/blog/tag/mongodb/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to connect to MongoDB Atlas Replica Set Cluster in SSIS</title>
		<link>https://zappysys.com/blog/connect-mongodb-atlas-ssis-replicaset/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Tue, 12 May 2020 17:41:27 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB Connection]]></category>
		<category><![CDATA[atlas]]></category>
		<category><![CDATA[MongoDB]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=8888</guid>

					<description><![CDATA[<p>Introduction In our previous post, we discovered how to read and write MongoDB data using ZappySys MongoDB Source and Destination SSIS connectors. However, it was all about connecting to the on-premises hosted version of MongoDB. In this post, we will focus on connecting specifically to the Replica Set Cluster in MongoDB Atlas (a cloud database service by MongoDB). After [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/connect-mongodb-atlas-ssis-replicaset/">How to connect to MongoDB Atlas Replica Set Cluster in SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><img decoding="async" class="size-full wp-image-2115 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png" alt="" width="88" height="88" />In our previous post, we discovered how to read and write MongoDB data using <a href="https://zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">ZappySys MongoDB Source</a> and <a href="https://zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/" target="_blank" rel="noopener">Destination</a> SSIS connectors. However, it was all about connecting to the on-premises hosted version of MongoDB. In this post, we will focus on connecting specifically to the <em>Replica Set Cluster </em>in <a href="https://www.mongodb.com/atlas/database" target="_blank" rel="noopener"><em>MongoDB Atlas</em></a> (a cloud database service by MongoDB). After you complete the steps listed below, you will be able to get and push data using the same MongoDB SSIS connectors, but this time — in MongoDB Atlas. Let&#8217;s not waste our precious time and begin!</p>
<div class="content_block" id="custom_post_widget-2523"><h2><span id="Prerequisites">Prerequisites</span></h2>
Before we perform the steps listed in this article, you will need to make sure the following prerequisites are met:
<ol style="margin-left: 1.5em;">
 	<li><abbr title="SQL Server Integration Services">SSIS</abbr> designer installed. Sometimes it is referred to as <abbr title="Business Intelligence Development Studio">BIDS</abbr> or <abbr title="SQL Server Data Tools">SSDT</abbr> (<a href="https://docs.microsoft.com/en-us/sql/ssdt/download-sql-server-data-tools-ssdt" target="_blank" rel="noopener">download it from the Microsoft site</a>).</li>
 	<li>Basic knowledge of SSIS package development using <em>Microsoft SQL Server Integration Services</em>.</li>
 	<li>Make sure <span style="text-decoration: underline;"><a href="https://zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">ZappySys SSIS PowerPack</a></span> is installed (<a href="https://zappysys.com/products/ssis-powerpack/download/" target="_blank" rel="noopener">download it</a>, if you haven't already).</li>
 	<li>(<em>Optional step</em>)<em>.</em> <a href="https://zappysys.zendesk.com/hc/en-us/articles/360035974593" target="_blank" rel="noopener">Read this article</a>, if you are planning to deploy packages to a server and schedule their execution later.</li>
</ol></div>
<h2>MongoDB Atlas connection setup in SSIS</h2>
<p>In this article, we are going to demonstrate how to create the <em>MongoDB Connection Manager, </em>which is used by <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/">MongoDB ExecuteSQL Task</a>, <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/">MongoDB Source,</a> and <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/">MongoDB Destination</a> SSIS connectors. Let&#8217;s start by following these simple steps:</p>
<ol style="margin-left: 1.5em;">
<li>First, <a href="https://zappysys.com/products/ssis-powerpack/download/" target="_blank" rel="noopener">download and install SSIS PowerPack</a>.</li>
<li>Once you installed SSIS PowerPack, open Visual Studio, and create a new SSIS project with a new SSIS package.</li>
<li>Then open the created package and right-click on the <em>Connection Managers</em> panel to create a new MongoDB connection. When a context menu appears, select the <em>New Connection&#8230;</em> menu item:<br />
<img decoding="async" class="figureimage" title="SSIS Create New Connection" src="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/ssis-new-connection.png" alt="SSIS Create New Connection" /></li>
<li>Next, select the <em>ZS-MONGODB</em> option from the connection manager list and click <em>Add&#8230;</em> button:<br />
<img decoding="async" class="figureimage" title="MongoDB Storage Connection" src="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/mongodb-connection/ssis-mongodb-executesql-task-connection.png" alt="MongoDB Connection" /></li>
<li>This will open the <em>MongoDB Connection Manager</em> configuration window. For now, let&#8217;s leave it open, and first go to your <a href="https://cloud.mongodb.com/" target="_blank" rel="noopener">MongoDB Atlas account</a> to get all MongoDB Atlas Cluster instance information for <em>MongoDB Connection Manager </em>configuration<em>.</em></li>
<li>Once you are on the MongoDB Atlas landing page, continue by selecting the cluster you want to connect to (<a href="https://docs.mongodb.com/guides/cloud/connectionstring/" target="_blank" rel="noopener">make sure you white-list your IP first</a>). After the window appears, select the <em>Compass</em> option:
<div id="attachment_10417" style="width: 753px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/connect-mongodb-atlas-ssis-replicaset/01-mongodb-atlas-select-shell-option-to-connect-to-ssis-3/#main" rel="noopener"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-10417" class="wp-image-10417 size-full" src="https://zappysys.com/blog/wp-content/uploads/2020/05/01-MongoDB-Atlas-select-shell-option-to-connect-to-SSIS-2.png" alt="" width="743" height="473" srcset="https://zappysys.com/blog/wp-content/uploads/2020/05/01-MongoDB-Atlas-select-shell-option-to-connect-to-SSIS-2.png 743w, https://zappysys.com/blog/wp-content/uploads/2020/05/01-MongoDB-Atlas-select-shell-option-to-connect-to-SSIS-2-300x191.png 300w" sizes="(max-width: 743px) 100vw, 743px" /></a><p id="caption-attachment-10417" class="wp-caption-text">Connecting to MongoDB Atlas Replica Set Cluster</p></div></li>
<li>Then proceed by simply copying and pasting the configuration information into the <em>MongoDB Connection Manager </em>we left to rest for a while. Move on by filling in your database credentials and the database you are connecting to. Also, don&#8217;t forget to enable SSL. Just patiently follow the numbers in orange circles below and you will be done faster than you think!
<div id="attachment_10415" style="width: 843px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/connect-mongodb-atlas-ssis-replicaset/02-mongodb-atlas-copy-the-connection-string-to-use-in-ssis-or-odbc-3/#main" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-10415" class="wp-image-10415 size-full" src="https://zappysys.com/blog/wp-content/uploads/2020/05/02-MongoDB-Atlas-copy-the-connection-string-to-use-in-SSIS-or-ODBC-2.png" alt="" width="833" height="1289" srcset="https://zappysys.com/blog/wp-content/uploads/2020/05/02-MongoDB-Atlas-copy-the-connection-string-to-use-in-SSIS-or-ODBC-2.png 833w, https://zappysys.com/blog/wp-content/uploads/2020/05/02-MongoDB-Atlas-copy-the-connection-string-to-use-in-SSIS-or-ODBC-2-194x300.png 194w, https://zappysys.com/blog/wp-content/uploads/2020/05/02-MongoDB-Atlas-copy-the-connection-string-to-use-in-SSIS-or-ODBC-2-768x1188.png 768w, https://zappysys.com/blog/wp-content/uploads/2020/05/02-MongoDB-Atlas-copy-the-connection-string-to-use-in-SSIS-or-ODBC-2-662x1024.png 662w" sizes="(max-width: 833px) 100vw, 833px" /></a><p id="caption-attachment-10415" class="wp-caption-text">Configuring MongoDB Atlas connection in SSIS by setting the host, user name, password, and database options</p></div>
<div id="attachment_8892" style="width: 616px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-8892" class="wp-image-8892 size-full" src="https://zappysys.com/blog/wp-content/uploads/2020/05/ssis-mongodb-atlas-connection-replicaset-options.png" alt="Specify Replica Set Name" width="606" height="295" srcset="https://zappysys.com/blog/wp-content/uploads/2020/05/ssis-mongodb-atlas-connection-replicaset-options.png 606w, https://zappysys.com/blog/wp-content/uploads/2020/05/ssis-mongodb-atlas-connection-replicaset-options-300x146.png 300w" sizes="(max-width: 606px) 100vw, 606px" /><p id="caption-attachment-8892" class="wp-caption-text">Specifying MongoDB connection string options (i.e. <em>replicaSet</em> and <em>authSource</em> options)</p></div>
<div id="attachment_8891" style="width: 614px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-8891" class="wp-image-8891 size-full" src="https://zappysys.com/blog/wp-content/uploads/2020/05/ssis-mongodb-enable-ssl-encrypt.png" alt="Enable SSL Connection - Required for MongoDB Atlas (Encrypted Data Transfer)" width="604" height="511" srcset="https://zappysys.com/blog/wp-content/uploads/2020/05/ssis-mongodb-enable-ssl-encrypt.png 604w, https://zappysys.com/blog/wp-content/uploads/2020/05/ssis-mongodb-enable-ssl-encrypt-300x254.png 300w" sizes="(max-width: 604px) 100vw, 604px" /><p id="caption-attachment-8891" class="wp-caption-text">Enabling SSL Connection in MongoDB Connection Manager in SSIS (for encrypted data transfer)</p></div></li>
<li>Finally, press the <em>Test Connection</em> button to test the connection. If the test is successful, you can move on and start performing data operations on the MongoDB collections.</li>
</ol>
<p>That&#8217;s it — you can now use the <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/">MongoDB ExecuteSQL Task</a>, <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/">MongoDB Source,</a> and <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/">MongoDB Destination</a> as described in the below articles:</p>
<ul>
<li><a href="https://zappysys.com/blog/call-mongodb-javascript-using-ssis-execute-sql-task/" target="_blank" rel="noopener">How to call MongoDB JavaScript using SSIS<br />
</a></li>
<li><a title="Permalink to Read MongoDB data from array (extract nested sub documents)" href="https://zappysys.com/blog/read-mongodb-data-from-array-extract-nested-sub-documents/" target="_blank" rel="bookmark noopener">How to read MongoDB data from an array (extract nested subdocuments)</a></li>
<li><a title="Permalink to How to write MongoDB Aggregation Queries in SSIS (Group By)" href="https://zappysys.com/blog/aggregate-mongodb-data-using-group-by-query-in-ssis/" target="_blank" rel="bookmark noopener">How to write MongoDB Aggregation Queries in SSIS (Group By)</a></li>
<li><a title="Permalink to SSIS – Loading data into MongoDB (Upsert, Delete, Update)" href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/" target="_blank" rel="bookmark noopener">How to load SQL data into MongoDB (Insert, Upsert, Delete, Update)</a></li>
<li><a title="Permalink to Update MongoDB Array Items using SSIS" href="https://zappysys.com/blog/update-mongodb-array-items-using-ssis/" target="_blank" rel="bookmark noopener">How to update MongoDB Array Items using SSIS</a></li>
</ul>
<p>The post <a href="https://zappysys.com/blog/connect-mongodb-atlas-ssis-replicaset/">How to connect to MongoDB Atlas Replica Set Cluster in SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Update or Insert &#8211; Upsert MongoDB Array Items using SSIS</title>
		<link>https://zappysys.com/blog/update-insert-upsert-mongodb-array-items-ssis/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Wed, 13 Feb 2019 15:36:07 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB Destination]]></category>
		<category><![CDATA[SSIS Template Transform]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[upsert]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=6346</guid>

					<description><![CDATA[<p>Introduction In our previous blog post we saw how to update / delete mongodb array item. Now let&#8217;s look at how to Upsert MongoDB Array Items (i.e. Insert Item if not found in Array else Update existing record). Upsert into nested MongoDB Array requires two step process, unfortunately there is no easy way to do [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/update-insert-upsert-mongodb-array-items-ssis/">Update or Insert &#8211; Upsert MongoDB Array Items using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p>In our previous blog post we saw how to <a href="https://zappysys.com/blog/update-mongodb-array-items-using-ssis/" target="_blank" rel="noopener">update / delete mongodb array item</a>. Now let&#8217;s look at how to Upsert MongoDB Array Items (i.e. Insert Item if not found in Array else Update existing record). Upsert into nested MongoDB Array requires two step process, unfortunately there is no easy way to do in a single step. You may see in below screenshot that first we will do Update Step for Existing MongoDB Array Items and then we will insert missing Records in second step. So let&#8217;s get started.</p>
<div class="content_block" id="custom_post_widget-2523"><h2><span id="Prerequisites">Prerequisites</span></h2>
Before we perform the steps listed in this article, you will need to make sure the following prerequisites are met:
<ol style="margin-left: 1.5em;">
 	<li><abbr title="SQL Server Integration Services">SSIS</abbr> designer installed. Sometimes it is referred to as <abbr title="Business Intelligence Development Studio">BIDS</abbr> or <abbr title="SQL Server Data Tools">SSDT</abbr> (<a href="https://docs.microsoft.com/en-us/sql/ssdt/download-sql-server-data-tools-ssdt" target="_blank" rel="noopener">download it from the Microsoft site</a>).</li>
 	<li>Basic knowledge of SSIS package development using <em>Microsoft SQL Server Integration Services</em>.</li>
 	<li>Make sure <span style="text-decoration: underline;"><a href="https://zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">ZappySys SSIS PowerPack</a></span> is installed (<a href="https://zappysys.com/products/ssis-powerpack/download/" target="_blank" rel="noopener">download it</a>, if you haven't already).</li>
 	<li>(<em>Optional step</em>)<em>.</em> <a href="https://zappysys.zendesk.com/hc/en-us/articles/360035974593" target="_blank" rel="noopener">Read this article</a>, if you are planning to deploy packages to a server and schedule their execution later.</li>
</ol></div>
<h2>MongoDB Array Upsert &#8211; Update / Insert using Custom JOIN condition (such as $ne )</h2>
<p>By default SSIS Mongodb Destination performs Lookup using $eq condition (Match rows using Equal operator). However there will be a time when you like to lookup and update target rows using custom join criteria (e.g. Use Not Equal condition &#8211; $ne ). V2.7.6  and later introduced new property called  <pre class="crayon-plain-tag">EnableCustomLookupQuery</pre> . When you enable this setting, you can supply a document which contains Data and Condition. You can map this XML formatted document to   __DOCUMENT__  (see below)</p>
<p>Here is the description how to use custom Join using this new property.</p><pre class="crayon-plain-tag">Enables use of custom lookup query for Update / Upsert or Delete Operation. 
By default JOIN condition for target record match is generated automatically based on columns you supply in ColumnsForLookup property. 
However in some cases you need to supply custom condition for lookup to perform complex operations, in such case enable this option. 
When you enable this option you must supply map __DOCUMENT__ input column. String you supply to this column should be in this format 

&lt;command&gt;
  &lt;query&gt;YOUR_LOOKUP_QUERY&lt;/query&gt;
  &lt;document&gt;YOUR_JSON_DOC&lt;/document&gt;
&lt;/command&gt;. 

Lookup query in &lt;query&gt; tag can be either Mongo JSON format (e.g. { \"CustomerID\" : \"AAA\", \"Orders.OrderID\" : { \"$ne\" : \"1000\" } }) 
OR
you can use ZappySys SQL query (e.g. select * from mytable where CustomerID='AAA' and [Orders.$.OrderID] != '1000' )</pre><p>
Now lets look at step by step. In below example we have a table called CustomerTest. We will load it with 2 records (With No orders). Then Update array using custom lookup condition, and later step we will insert record in array using custom lookup condition.</p>
<div id="attachment_6299" style="width: 498px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-upsert-example.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6299" class="size-full wp-image-6299" src="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-upsert-example.png" alt="SSIS MongoDB Array Upsert Example (Update / Insert Array Items based on custom lookup condition)" width="488" height="346" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-upsert-example.png 488w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-upsert-example-300x213.png 300w" sizes="(max-width: 488px) 100vw, 488px" /></a><p id="caption-attachment-6299" class="wp-caption-text">SSIS MongoDB Array Upsert Example (Update / Insert Array Items based on custom lookup condition)</p></div>
<h3>Update Array using Custom Lookup Condition</h3>
<ol>
<li>Lets create few sample rows in MongoDB Collection. You can use following command in SSIS MongoDB Execute SQL Task<br />
<pre class="crayon-plain-tag">{
 scope: 'database',
 db: 'Northwind',
 command: 'eval',
 args: 
 {
 code: 'db.CustomerTest.insert( [ {CustomerID:"AAA", Orders:[]}, {CustomerID:"BBB", Orders:[]}, {CustomerID:"CCC", Orders:[{OrderID:"1004","OrderDate" : "2008-02-05","Qty" : "5"} ]} ] )' 
 
 } 
}</pre>
</li>
<li>Now drag Data flow.</li>
<li>Drag <a href="https://zappysys.com/products/ssis-powerpack/ssis-csv-file-source-flat-file-web-api/" target="_blank" rel="noopener">ZS CSV Source</a> or any other source. For example purpose we will configure CSV Source using Direct Value option with following Sample data. In the first run of package it will update only orders for CCC customer because only that customer will have records after table creation. one row. But in 2nd run all rows updated.<br />
<pre class="crayon-plain-tag">CustomerID,Company,OrderID,OrderDate,Qty,Address
AAA,Anthony Inc,1000,2008-01-01,90,Po Box 111\4612
AAA,Anthony Inc,1001,2010-02-01,91,Po Box 111 / 4612
BBB,Bob Inc,1002,2008-02-01,92,Po Box 222 / 4612
BBB,Bob Inc,1003,2010-01-01,93,Po Box 222 / 4612
CCC,Cindy Inc,1004,2010-01-07,2,Po Box 555 / 2345</pre>
&nbsp;</li>
<li>Click OK to save Source UI</li>
<li>Now drag ZS Template Transform to build XML document (Data + Query). Connect Source to Template transform. You can also use ZS XML Generator Transform but for simplicity we will use Template Transform.</li>
<li>Double click to open Template Transform and enter text as below. Notice how we have entered MongoDB Query and Data in two separate XML nodes. First node is custom query for lookup. Second node is Operation we like to perform (e.g. $set in our case to update existing data). You can use Insert Variable and then select Columns option to insert placeholders. Also in some fields we used JSONENCODE function to make sure we escape double quote and slash correctly.<br />
<pre class="crayon-plain-tag">&lt;command&gt;
	&lt;query&gt;&lt;![CDATA[
{
	"CustomerID": "&lt;%CustomerID%&gt;", 
	"Orders.OrderID": { "$eq" : "&lt;%OrderID%&gt;"}
}
]]&gt;&lt;/query&gt;
	&lt;document&gt;&lt;![CDATA[
{
  $set :
   { "CompanyName":"&lt;%Company,JSONENCODE%&gt;", 
     "Address":"&lt;%Address,JSONENCODE%&gt;", 
     "Orders.$.OrderID": "&lt;%OrderID%&gt;", 
     "Orders.$.OrderDate": "&lt;%OrderDate%&gt;", 
     "Orders.$.Qty": "&lt;%Qty%&gt;" 
    } 
  }
}
]]&gt;&lt;/document&gt;
&lt;/command&gt;</pre>
<div id="attachment_6300" style="width: 851px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-update-custom-lookup-template-transform.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6300" class="size-full wp-image-6300" src="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-update-custom-lookup-template-transform.png" alt="Using ZS Template Transform to specify custom JOIN condition for MongoDB Update (Array Items)" width="841" height="697" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-update-custom-lookup-template-transform.png 841w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-update-custom-lookup-template-transform-300x249.png 300w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-update-custom-lookup-template-transform-768x636.png 768w" sizes="(max-width: 841px) 100vw, 841px" /></a><p id="caption-attachment-6300" class="wp-caption-text">Using ZS Template Transform to specify custom JOIN condition for MongoDB Update (Array Items)</p></div></li>
<li>Click OK to save Template Transform</li>
<li>Drag ZS MongoDB Destination. Connect Template Transform to Destination</li>
<li>Double click MongoDB Destination to edit. Set Connection, Table name, Operation=Update, <strong>EnableCustomLookupQuery</strong>=True
<div id="attachment_6301" style="width: 638px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-update-custom-condition-setting.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6301" class="size-full wp-image-6301" src="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-update-custom-condition-setting.png" alt="Configure MongoDB Destination for Custom Join Condition (EnableCustomLookupQuery Setting)" width="628" height="613" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-update-custom-condition-setting.png 628w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-update-custom-condition-setting-300x293.png 300w" sizes="(max-width: 628px) 100vw, 628px" /></a><p id="caption-attachment-6301" class="wp-caption-text">Configure MongoDB Destination for Custom Join Condition (EnableCustomLookupQuery Setting)</p></div></li>
<li>Goto Mappings Tab and attach TemplateOutput to __DOCUMENT__
<div id="attachment_6302" style="width: 717px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-custom-join-mapping.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6302" class="size-full wp-image-6302" src="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-custom-join-mapping.png" alt="MongoDB Mappings - Loading Document for Array Update (Custom Join Criteria)" width="707" height="584" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-custom-join-mapping.png 707w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-custom-join-mapping-300x248.png 300w" sizes="(max-width: 707px) 100vw, 707px" /></a><p id="caption-attachment-6302" class="wp-caption-text">MongoDB Mappings &#8211; Loading Document for Array Update (Custom Join Criteria)</p></div></li>
<li>Click OK to Save</li>
</ol>
<p>&nbsp;</p>
<h3>Insert into Array using Custom Lookup Condition</h3>
<p>Now let&#8217;s look at slightly modified steps to Insert into Array for new records. In this example we will insert Source records if CustomerID found but OrderID is not found. (See Template Transform Step). We will use <strong>Not Equal Condition</strong> this time.</p>
<ol>
<li>Now drag Data flow rename it to something like <strong>[Add records to array]</strong></li>
<li>Drag ZS CSV Source or any other source. For example purpose we will configure CSV Source using Direct Value option with following Sample data<br />
<pre class="crayon-plain-tag">CustomerID,Company,OrderID,OrderDate,Qty
AAA,Anthony Inc,1000,2008-01-01,30
AAA,Anthony Inc,1001,2010-02-01,4
BBB,Bob Inc,1002,2008-02-01,30
BBB,Bob Inc,1003,2010-01-01,4</pre>
&nbsp;</li>
<li>Click OK to save Source UI</li>
<li>Now drag ZS Template Transform to build XML document (Data + Query). Connect Source to Template transform. You can also use ZS XML Generator Transform but for simplicity we will use Template Transform.</li>
<li>Double click to open Template Transform and enter text as below. Notice how we have entered MongoDB Query and Data in two separate XML nodes. First node is custom query for lookup. Second node is Operation we like to perform (e.g. $addToSet in our case to insert into array )<br />
<pre class="crayon-plain-tag">&lt;command&gt;
&lt;query&gt;
{"CustomerID": "&lt;%CustomerID%&gt;", "Orders.OrderID":{ "$ne" : "&lt;%OrderID%&gt;"}}
&lt;/query&gt;
&lt;document&gt;{
  $addToSet :
   { Orders : {"OrderID": "&lt;%OrderID%&gt;", "OrderDate": "&lt;%OrderDate%&gt;", "Qty": "&lt;%Qty%&gt;" } }    
 }
&lt;/document&gt;
&lt;/command&gt;</pre>
</li>
<li>Click OK to save Template Transform</li>
<li>Drag ZS MongoDB Destination. Connect Template Transform to Destination</li>
<li>Double click MongoDB Destination to edit. Set Connection, Table name, Operation=Update, <strong>EnableCustomLookupQuery</strong>=True</li>
<li>Goto Mappings Tab and attach TemplateOutput to __DOCUMENT__</li>
<li>Click OK to Save</li>
</ol>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2017/01/MongoDB_Upsert_ArrayItem.zip">Download Sample SSIS Package (2012 format) &#8211; MongoDB_Upsert_ArrayItem</a></p>
<p>&nbsp;</p>
<h2>Conclusion</h2>
<p>MongoDB integration can be challenging if you are new to NoSQL world. If you are using SSIS as your primary ETL tool then not to worry because <a href="//zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">SSIS PowerPack</a> can give super power needed to complete your project on time with drag and drop high performance connectors.</p>
<p>Keywords: ssis mongodb upsert array item | ssis mongodb update array item | ssis mongodb update array elements | mongodb update array documents | MongoDB $set operator | MongoDB $addToSet operator | MongoDB update sub document items | MongoDB CRUD operations | MongoDB Bulk Updates | MongoDB bulk updates to array items</p>
<p>&nbsp;</p>
<p>The post <a href="https://zappysys.com/blog/update-insert-upsert-mongodb-array-items-ssis/">Update or Insert &#8211; Upsert MongoDB Array Items using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to configure MongoDB SSL Connection in SSIS</title>
		<link>https://zappysys.com/blog/configure-mongodb-ssl-connection-certificate/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Tue, 29 Aug 2017 19:50:01 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB Source]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[pem]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[SSIS PowerPack]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[X509]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=1719</guid>

					<description><![CDATA[<p>Introduction MongoDB comes with SSL support, which can secure your end-to-end communication. However, setting up a MongoDB SSL Connection may require some configuration on both sides (i.e., Server and Client side). In this post, we aim to secure your MongoDB Integration in SSIS. Now, let&#8217;s look at the steps to configure SSL in MongoDB. Configure [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/configure-mongodb-ssl-connection-certificate/">How to configure MongoDB SSL Connection in SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png"><img loading="lazy" decoding="async" class="size-full wp-image-2115 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png" alt="" width="88" height="88" /></a>MongoDB comes with SSL support, which can secure your end-to-end communication. However, setting up a MongoDB SSL Connection may require some configuration on both sides (i.e., Server and Client side). In this post, we aim to secure your <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-integration-pack/" target="_blank" rel="noopener">MongoDB Integration in SSIS</a>.</p>
<p>Now, let&#8217;s look at the steps to configure SSL in MongoDB.</p>
<h2>Configure SSL Support in MongoDB Server</h2>
<p>To configure MongoDB for SSL connectivity, the very first step is to generate a self-signed certificate in <a href="http://how2ssl.com/articles/working_with_pem_files/" target="_blank" rel="noopener">*.pem format</a> (This must be stored on the server)</p>
<h3>Download and Install OpenSSL</h3>
<p>First step is to <a href="http://slproweb.com/products/Win32OpenSSL.html" target="_blank" rel="noopener">download and install OpenSSL</a>. <span style="box-sizing: border-box; margin: 0px; padding: 0px;">Assuming you are running <strong>a </strong><span style="box-sizing: border-box; margin: 0px; padding: 0px;"><strong>64 Bit Windows</strong> OS, you can download the <strong>64 Bit Lite version</strong> of OpenSSL (about 3 </span>MB).</span> If you install it using default settings, then all binaries will be installed under <strong>C:\OpenSSL-Win64\bin\ </strong></p>
<h3>Create a self-signed certificate and *.pem file using OpenSSL.</h3>
<p>If you don&#8217;t have a trust issue and want to use a self-signed certificate rather than buying from a 3rd-party SSL Certificate Authority, you can create a self-signed certificate using the OpenSSL Command line as shown below. Now let&#8217;s look at how to generate a private key, a certificate file, and finally the *.pem file, which is the only required file by MongoDB.</p>
<p>A PEM file is the most common file format (container file format), which includes a Certificate and a Private Key in a single file.</p>
<p><span style="box-sizing: border-box; margin: 0px; padding: 0px;">Let&#8217;s look at how to <strong>create a PEM file using OpenSSL</strong>.</span></p>
<ol>
<li>First, run the command below. When prompted, enter &#8220;passphrase&#8221; (in our case, enter &#8220;test&#8221;).<br />
<pre class="crayon-plain-tag">openssl genrsa -des3 -out server.key 2048</pre>
</li>
<li>Now run the command below to <strong>generate a private key</strong> (*.key file)<br />
<pre class="crayon-plain-tag">openssl rsa -in server.key -out server.key</pre>
</li>
<li>After the private key is created, run the command below to <strong>create a CSR file</strong> (i.e., &#8220;Certificate Signing Request&#8221;). This file is needed to generate an actual certificate (Self-Signed or Signed by a 3rd Party, such as VeriSign or RapidSSL). If you omit the sub argument from below, then it may ask you a few questions (e.g, company name, department, etc), but for testing purposes, let&#8217;s make it easy 🙂<br />
To enter full details or just provide CN=xxxx<br />
<pre class="crayon-plain-tag">openssl req -sha256 -new -key server.key -out server.csr -subj &quot;/C=US/ST=Georgia/L=Atlanta/O=ZappySys LLC/OU=Org/E=testuser@zappysys.com/CN=localhost&quot;
-- or --
openssl req -sha256 -new -key server.key -out server.csr -subj &quot;/CN=localhost&quot;</pre>
</li>
<li>Now, let&#8217;s run the command below to <strong>generate a certificate file</strong> (*.crt). We are setting the expiration to 365 days; you can adjust as per your needs.<br />
<pre class="crayon-plain-tag">openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt</pre>
</li>
<li>Now, the last step is to <strong>combine the certificate (*.crt) and private key (*.key)</strong> <strong>files<strong> into a single </strong>PEM file</strong> using the command below. It will generate the desired *.pem file format, which can be used by the MongoDB server (In Unix OS, you can use the <strong>cat command</strong> rather than <strong>typing</strong>)<br />
<pre class="crayon-plain-tag">type server.crt server.key &gt; cert.pem</pre>
</li>
</ol>
<p>Once done, your <strong>cert.pem</strong> file will look like the following (Open and view in Notepad)</p><pre class="crayon-plain-tag">-----BEGIN CERTIFICATE-----
MIIDjjCCAnYCCQCDKO4/pCBfqTANBgkqhkiG9w0BAQsFADCBiDELMAkGA1UEBhMC
VVMxCzAJBgNVBAgMAkdBMRAwDgYDVQQHDAdBdGxhbnRhMREwDwYDVQQKDAhaYXBw
eVN5czELMAkGA1UECwwCSVQxFTATBgNVBAMMDHphcHB5c3lzLmNvbTEjMCEGCSqG
RF5DmNx6gKlRWlOFmokMCz7wAglErDL4h/I3w6iZaVVkBmeDj30cms/fQ+upAI8U
KrBpNEwOglU9fjqjpnW0u8qGpXIk3NfdCm+6Lr91GL/u/9+gmSYw5YCCF6kYaRA/
2mqLXZ3Xp6WfTfVyQskKMB9D1+7QljqBZmFnTjLCaJ9MdJzzMpFyWPRB4Ix1kAzV
yZk=
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAyo++fr54Wh8anfEDZrr5O1NXwrPZW6KI3dPQ8FVHVDcBPETi
VX3qGcq8vywXH/LdwMEC4EQGED+zo50GmQdNiIzUfsnDbkq6rkqVNKjh7agkDlip
5vK3yuHtYAVp+laJ8X8kKISRttY7kcnl9gSkfTilwpN8//49G45Nx0JFu3o3Ortb
H4FPWjidQBAA6hPxoQi2h7YfEfpICL1RwYDCaQpdwMEJJqzcvaHCpdYVYd5PHLks
xRi8iwKBgA/S5w4/pwrzq0Jab/Afzf8AleZm/xLmXFpglgZF25AtVhpnayoHiTIk
9BdCXydi0ZOg4LtMqkSwt427UWCEnoRRH1WbKH2F9ZRWaELw/ix9RrZgTNmF821F
1/ILtO+QrN8tFnrLX3NAWurxUJxvzhBnvq40ZIHCyWvhRXUTkzTH
-----END RSA PRIVATE KEY-----</pre><p>
&nbsp;</p>
<h3>Edit the MongoDB Server config file (v3.0 or higher)</h3>
<p>Now that we have the *.pem file, we can use it to launch a MongoDB server instance. Before we do that, one more step is needed. We have to specify a few parameters in the MongoDB config file.</p>
<ol>
<li>Navigate to the MongoDB installation directory (where <strong>mongod.exe</strong> is found)</li>
<li>Create an empty text file called mongo-config.txt and enter the following text (assuming cer.pem, mongo-config.txt, and all mongod.exe are in the same folder). The password was tested when we created the PEM file. If you used a different one, then change it below.<br />
<strong>mongo-config.txt</strong><br />
<pre class="crayon-plain-tag">net:  
    bindIp: localhost
    ssl:
        mode: requireSSL
        PEMKeyFile: cert.pem
        PEMKeyPassword: test
        allowInvalidCertificates: true
        allowInvalidHostnames: true</pre>
</li>
</ol>
<h3>Start the MongoDB Server using the Config file</h3>
<p>Once you create a config file, we can start the MongoDB instance using the following command line to use the new config file with SSL mode enabled. That&#8217;s it, your server is now accepting Secure connections using SSL.</p><pre class="crayon-plain-tag">mongod -f &quot;mongod-config.txt&quot;</pre><p>
<h2>Using the SSL option in the SSIS MongoDB Connection</h2>
<p>Now, let&#8217;s look at the steps to secure the MongoDB connection in SSIS.</p>
<h3><span id="Prerequisites">Prerequisites</span></h3>
<p>Before we look at the Step-By-Step section on securing the MongoDB Connection in SSIS, let&#8217;s make sure you meet the following requirements.</p>
<ol>
<li>SSIS designer installed. Sometimes it is referred to as BIDS or SSDT (<a href="https://docs.microsoft.com/en-us/sql/ssdt/download-sql-server-data-tools-ssdt" target="_blank" rel="noopener">download it from the Microsoft site</a>).</li>
<li>Basic knowledge of SSIS package development using <em>Microsoft SQL Server Integration Services</em>.</li>
<li><a href="//zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener"><em>ZappySys SSIS PowerPack</em> installed</a>. Click on the link to download a FREE trial.</li>
<li>You have basic familiarity with MongoDB.</li>
</ol>
<h3>Using SSL in the SSIS MongoDB Connection Manager</h3>
<p>To enable SSL in SSIS, open the MongoDB connection manager and go to the SSL Tab. Check the Enable SSL option as shown below. Once you do this, and if your MongoDB server is configured correctly to use SSL, then your connection Test will be green, and any traffic between you and your MongoDB server will be encrypted using SSL.</p>
<div id="attachment_11646" style="width: 1035px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2017/08/SSIS-MongoDB-Connection-SSL-Settings.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-11646" class="wp-image-11646 size-full" src="https://zappysys.com/blog/wp-content/uploads/2017/08/SSIS-MongoDB-Connection-SSL-Settings.png" alt="" width="1025" height="540" srcset="https://zappysys.com/blog/wp-content/uploads/2017/08/SSIS-MongoDB-Connection-SSL-Settings.png 1025w, https://zappysys.com/blog/wp-content/uploads/2017/08/SSIS-MongoDB-Connection-SSL-Settings-300x158.png 300w, https://zappysys.com/blog/wp-content/uploads/2017/08/SSIS-MongoDB-Connection-SSL-Settings-768x405.png 768w, https://zappysys.com/blog/wp-content/uploads/2017/08/SSIS-MongoDB-Connection-SSL-Settings-720x380.png 720w" sizes="(max-width: 1025px) 100vw, 1025px" /></a><p id="caption-attachment-11646" class="wp-caption-text">SSIS MongoDB Connection &#8211; SSL Settings</p></div>
<h3>Using X509 Client Authentication in SSIS MongoDB Connection Manager</h3>
<p>Now, let&#8217;s look at how to authenticate using the X509 Client Certificate (X509) method. For this method, you must use the PFX certificate format (do not use PEM). To create a PFX file from the PEM we created earlier, you can run the following command. When prompted, use the same password you used before to generate a private key.</p><pre class="crayon-plain-tag">openssl pkcs12 -export -out cert.pfx -inkey server.key -in server.crt</pre><p>
<span style="box-sizing: border-box; margin: 0px; padding: 0px;">To learn more about the whole process of how to configure the MongoDB Server to use Client X509 Certificate, <a href="https://github.com/shauryashaurya/tutorial-x.509certificates-mongo" target="_blank" rel="noopener">check this Article</a>.</span></p>
<p>Let&#8217;s look at the steps to configure the SSIS MongoDB Connection Manager to use X509 Client Certificate Mode.</p>
<ol>
<li>Open ZappySys MongoDB Connection Manager UI</li>
<li>Enter the User ID you created in the <strong>$external</strong> database (This UserID usually matches the Subject of your Certificate). For example, in our case, UserID may appear as follows. Leave the password blank because it&#8217;s not used in the X. 509 method.<br />
<pre class="crayon-plain-tag">emailAddress=user@myemail.com,CN=127.0.0.1,OU=UNIT,O=DEMO,L=city,ST=test,C=AU</pre>
<div id="attachment_11644" style="width: 628px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Set-UserID-of-external-database.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-11644" class="wp-image-11644 size-full" src="https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Set-UserID-of-external-database.png" alt="" width="618" height="540" srcset="https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Set-UserID-of-external-database.png 618w, https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Set-UserID-of-external-database-300x262.png 300w" sizes="(max-width: 618px) 100vw, 618px" /></a><p id="caption-attachment-11644" class="wp-caption-text">Configure SSIS MongoDB Connection for Client X509 Certificate (Set UserID of $external database)</p></div>
<div class="mceTemp"></div>
</li>
<li> Now go to the SSL Tab. Check SSL Option, You can check Ignore SSL Validation error (If it&#8217;s a signed certificate)</li>
<li>Select the PFX file path and enter the certificate password if needed. If you type Path, then Subject Line appears automatically (You can use it as UserID field if you were unsure in Step#1 however, we still recommend making sure UserID is an  exact match based on the original name your System Admin created in <strong>$external</strong> DB)
<div class="mceTemp"></div>
<div id="attachment_11643" style="width: 571px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Select-PFX-File-Specify-Password.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-11643" class="wp-image-11643 size-full" src="https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Select-PFX-File-Specify-Password.png" alt="" width="561" height="541" srcset="https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Select-PFX-File-Specify-Password.png 561w, https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Select-PFX-File-Specify-Password-300x289.png 300w" sizes="(max-width: 561px) 100vw, 561px" /></a><p id="caption-attachment-11643" class="wp-caption-text">Configure SSIS MongoDB Connection for Client X509 Certificate (Select PFX File &#8211; Specify Password)</p></div>
<div class="mceTemp"></div>
</li>
<li>Now go to the Advanced Tab and enter the Below Option. By default, MongoDB Connection Manager uses the userid/password mode. To use <strong>X509</strong> Auth mode, you must set an option in the Advanced Options table as shown below.<br />
<pre class="crayon-plain-tag">authMechanism=MONGODB-X509</pre>
<div id="attachment_11645" style="width: 571px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Specify-authMechanismMONGODB-X509.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-11645" class="wp-image-11645 size-full" src="https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Specify-authMechanismMONGODB-X509.png" alt="" width="561" height="541" srcset="https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Specify-authMechanismMONGODB-X509.png 561w, https://zappysys.com/blog/wp-content/uploads/2017/08/Configure-SSIS-MongoDB-Connection-for-Client-X509-Certificate-Specify-authMechanismMONGODB-X509-300x289.png 300w" sizes="(max-width: 561px) 100vw, 561px" /></a><p id="caption-attachment-11645" class="wp-caption-text">Configure SSIS MongoDB Connection for Client X509 Certificate (Specify authMechanism=MONGODB-X509)</p></div>
<div class="mceTemp"></div>
</li>
<li>Click Test connection to make sure it&#8217;s successful.</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://zappysys.com/blog/configure-mongodb-ssl-connection-certificate/">How to configure MongoDB SSL Connection in SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Update MongoDB Array Items using SSIS</title>
		<link>https://zappysys.com/blog/update-mongodb-array-items-using-ssis/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Sat, 21 Jan 2017 23:00:55 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB Destination]]></category>
		<category><![CDATA[SSIS MongoDB ExecuteSQL]]></category>
		<category><![CDATA[SSIS Template Transform]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[SSIS JSON Generator Transform]]></category>
		<category><![CDATA[ssis json source]]></category>
		<category><![CDATA[SSIS PowerPack]]></category>
		<category><![CDATA[upsert]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=952</guid>

					<description><![CDATA[<p>Introduction In our previous blog post we saw how to perform Read and Write operations in MongoDB using SSIS (i.e. Bulk Update, Delete, Upsert, Insert). In this post we specifically focus on how to update MongoDB Array items / elements using SSIS. To make things simple to follow we have used JSON Source to produce [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/update-mongodb-array-items-using-ssis/">Update MongoDB Array Items using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png"><img loading="lazy" decoding="async" class="size-full wp-image-2115 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png" alt="" width="88" height="88" /></a>In <a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/" target="_blank" rel="noopener">our previous blog post</a> we saw how to perform Read and Write operations in MongoDB using SSIS (i.e. Bulk Update, Delete, Upsert, Insert). In this post we specifically focus on <em>how to update MongoDB Array items / elements using SSIS</em>.</p>
<p>To make things simple to follow we have used <a href="//zappysys.com/products/ssis-powerpack/ssis-json-file-source/" target="_blank" rel="noopener">JSON Source</a> to produce sample JSON documents for MongoDB update (NOTE: Output as Document option is checked for JSON Source). However in real world you may have to use <a href="//zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/" target="_blank" rel="noopener">SSIS JSON Generator Transform</a> to produce input documents for MongoDB. To learn more about generating JSON documents for MongoDB Load process <a href="//zappysys.com/blog/create-mongodb-documents-ssis-json-bson-load-update-insert-upsert-collection/" target="_blank" rel="noopener">check this blog post</a> or watch video found <a href="//zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/" target="_blank" rel="noopener">on this page</a>.</p>
<h2>Video Tutorial &#8211; Example of insert/update documents inside MongoDB Array (Use $set, $push operator)</h2>
<a href="https://zappysys.com/blog/update-mongodb-array-items-using-ssis/"><img decoding="async" src="https://zappysys.com/blog/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FcaiLHfF-pzg%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p>
<h2>Basic Concepts: Performing MongoDB CRUD operations using SSIS</h2>
<p>If you never heard term called CRUD stands for Create, Read, Update, Delete. These are the most common operations you have to do with any data source. <a href="//zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">SSIS PowerPack</a> comes with many MongoDB Components to help you with CRUD operations. You can use one or more following components to achieve drag and drop MongoDB CRUD operations in SSIS. When you use SSIS PowerPack for MongoDB all operations will be Bulk Operations by default which means it will provide very high throughput.</p>
<ul>
<li><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">SSIS MongoDB Source</a></li>
<li><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/" target="_blank" rel="noopener">SSIS MongoDB Destination</a></li>
<li><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/" target="_blank" rel="noopener">SSIS MongoDB ExecuteSQL Task</a></li>
</ul>
<h2>Download Example SSIS Package</h2>
<p>Here is the link to <a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-array-update-sample-package.zip">download Sample SSIS Package</a></p>
<div id="attachment_958" style="width: 711px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-update-mongodb-array-items-delete-insert-set-push-pull.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-958" class="size-full wp-image-958" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-update-mongodb-array-items-delete-insert-set-push-pull.png" alt="SSIS Example : Update MongoDB Array Items / Elements (Update, Delete, Insert - Using $set, $pull, $push)" width="701" height="487" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-update-mongodb-array-items-delete-insert-set-push-pull.png 701w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-update-mongodb-array-items-delete-insert-set-push-pull-300x208.png 300w" sizes="(max-width: 701px) 100vw, 701px" /></a><p id="caption-attachment-958" class="wp-caption-text">SSIS Example : Update MongoDB Array Items / Elements (Update, Delete, Insert &#8211; Using $set, $pull, $push)</p></div>
<p>&nbsp;</p>
<h2>Update MongoDB Array Items ($set operator)</h2>
<p>In next couple of sections we will see how to perform Update, Insert and Delete operations with MongoDB Array Items using various <a href="https://docs.mongodb.com/manual/reference/operator/update/" target="_blank" rel="noopener">update operators</a> and <a href="https://docs.mongodb.com/manual/reference/operator/update-array/" target="_blank" rel="noopener">array operators</a>. Consider the following Sample JSON documents for MongoDB. First we will see how to use MongoDB Shell commands to perform CRUD operations on MongoDB Array items.</p><pre class="crayon-plain-tag">{
    "_id" : ObjectId("5883ebe669e0f22ba890b49b"),
    "CustomerID" : "BOLID",
    "Name" : "Some name",
    "Orders" : [ 
        {
            "OrderID" : 200,
            "ShipCountry" : "USA",
            "City" : "Atlanta"
        }, 
        {
            "OrderID" : 201,
            "ShipCountry" : "USA",
            "City" : "New York"
        }
    ]
}</pre><p>
<h3>Update Array element using Shell command</h3>
<p>Assume you want to update ShipCountry attribute of one of the Orders (OrderID=200) and for CustomerID=&#8221;BOLID&#8221; in above sample document.</p>
<h4>Shell Command for Update Array Item</h4>
<p>Use below shell command in your favorite MongoDB Client Tool (e.g. RoboMongo). Notice two things in below command because we will apply same concepts when we take this approach to SSIS. In below command Actual JSON document is wrapped inside. This is MongoDB Update operator. <a href="https://docs.mongodb.com/manual/reference/operator/update/set/" target="_blank" rel="noopener">Click here to learn more about $set</a>. Also notice that rather than nested Array syntax we used Orders.$.ShipCountry to update ShipCountry which is part of Array element. MongoDB provides special way to navigate array elements using   <a href="https://docs.mongodb.com/manual/reference/operator/update/positional/" target="_blank" rel="noopener">$ Operator (MongoDB Positional Update) </a></p><pre class="crayon-plain-tag">db.MyCollection.update(
	{ "CustomerID" : "BOLID", "Orders.OrderID" : 200 }, 
	{ $set : { "Orders.$.ShipCountry" : "Test1"} } , 
	{ upsert: false, multi: false}
)</pre><p>
<h4>After Update (MongoDB Document)</h4>
<p>After you run above shell command notice all other attributes remain there in Array document and only ShipCountry is changed. This is because we used <a href="https://docs.mongodb.com/manual/reference/operator/update/positional/" target="_blank" rel="noopener">$ Operator (MongoDB Positional Update) </a>rather than supplying Raw JSON for Array document (i.e. Orders : [ { &#8230; } ] ).</p><pre class="crayon-plain-tag">{
    "_id" : ObjectId("5883ebe669e0f22ba890b49b"),
    "CustomerID" : "BOLID",
    "Name" : "Some name",
    "Orders" : [ 
        {
            "OrderID" : 200,
            "ShipCountry" : "Test1",
            "City" : "Atlanta"
        }, 
        {
            "OrderID" : 201,
            "ShipCountry" : "USA",
            "City" : "New York"
        }
    ]
}</pre><p>
The issue with this approach its not Bulk operation. Assume that you have 100,000 records to update in various documents and its nested array items then row by row operation is not effective. To solve this issue we will use SSIS MongoDB Destination which performs Bulk operations (e.g. Bulk Update, Delete, Insert and Upsert).</p>
<h3>Update MongoDB Array Items using SSIS</h3>
<p>Now lets implement above scenario using SSIS. Assume that you have sample MongoDB document (as per above example &#8211; Before Update). We want to update ShipCountry for OrderID=200 for Customer BOLID. To do that perform following steps in SSIS. If you are updating Second level array (i.e. Root &gt;&gt; Orders &gt;&gt; OrderItems)  then you have follow slight different process. Check next section in this article about updating second level array (Insert items)</p>
<ol>
<li>Download and <a href="https://zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">Install SSIS PowerPack</a></li>
<li>Create new SSIS Project with one data flow task
<div id="attachment_8028" style="width: 470px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-8028" class="size-full wp-image-8028" src="https://zappysys.com/blog/wp-content/uploads/2019/02/drag-and-drop-data-flow-task.png" alt="" width="460" height="155" srcset="https://zappysys.com/blog/wp-content/uploads/2019/02/drag-and-drop-data-flow-task.png 460w, https://zappysys.com/blog/wp-content/uploads/2019/02/drag-and-drop-data-flow-task-300x101.png 300w" sizes="(max-width: 460px) 100vw, 460px" /><p id="caption-attachment-8028" class="wp-caption-text">Dragging and dropping Data Flow Task into Control Flow</p></div></li>
<li>Drag ZS JSON Source and check Output as Document option (as below sceenshot). You can use JSON Source is your JSON is stored inside file or Variable or coming from Some API call which eventually go into MongoDB. You can also use JSON Source for quick testing where you Hardcode JSON to feed to MongoDB.</li>
<li>Enter the following JSON in the text area. Click OK to save.<br />
<pre class="crayon-plain-tag">{"CustomerID":"BOLID", "Orders.$.OrderID":201, "Orders.$.ShipCountry": "Test1"}
{"CustomerID":"BOLID", "Orders.$.OrderID":202, "Orders.$.ShipCountry": "Test2"}
/**Below is extra record not found in destination - will be ignored in Update**/
{"CustomerID":"BOLID", "Orders.$.OrderID":203, "Orders.$.ShipCountry": "Test3"}</pre>
</li>
<li>Right click in Connections area and Create new ZS-MONGODB connection. Specify credentials and click Test before you hit OK to save.</li>
<li>Now drag ZS MongoDB Destination from SSIS Toolbox.</li>
<li>Select Runtime connection.</li>
<li>On the properties tab edit following properties
<ol>
<li>Set ColumnsForLookup property as below (Notice how we use 2 columns for JOIN. Also used AS keywords for 2nd Column so we have <em>&lt;column-from-input-doc&gt; AS &lt;column-for-server-side-find&gt;</em><br />
<strong><em>CustomerID,Orders.$.OrderID AS Orders.OrderID</em></strong></li>
<li>Set LoadOptions as below (Op is <a href="https://docs.mongodb.com/manual/reference/operator/update" target="_blank" rel="noopener">Update Operator</a> you like to use. In our case its <a href="https://docs.mongodb.com/manual/reference/operator/update/set/" target="_blank" rel="noopener">$set</a>, Multi=True means if multiple match found then all matching documents will be updated). If you want to use multiple update operators then you have to supply that from Input document and use <strong>op=none</strong> option rather <strong>op=$set</strong>.<br />
<strong><em>op=$set;multi=true</em></strong></li>
<li>Set Operation property to Update</li>
</ol>
</li>
<li>On the Mappings tab Map __DOCUMENT__ from upstream (In our case you will see same name column from JSON Source if you checked Output as Document option)</li>
<li>Click OK to save MongoDB Destination UI</li>
<li>Run package. You will notice after execution two orders of CustomerID=BOLID will be updated.</li>
</ol>
<div id="attachment_961" style="width: 853px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-json-source-read-raw-json-documents.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-961" class="size-full wp-image-961" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-json-source-read-raw-json-documents.png" alt="SSIS JSON Source - Read JSON (Raw Documents)" width="843" height="507" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-json-source-read-raw-json-documents.png 843w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-json-source-read-raw-json-documents-300x180.png 300w" sizes="(max-width: 843px) 100vw, 843px" /></a><p id="caption-attachment-961" class="wp-caption-text">SSIS JSON Source &#8211; Read JSON (Raw Documents)</p></div>
<h2></h2>
<div id="attachment_962" style="width: 749px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-update-mongodb-item-set-operator.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-962" class="size-full wp-image-962" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-update-mongodb-item-set-operator.png" alt="SSIS MongoDB Destination - Update MongoDB Array Item using $set update operator" width="739" height="469" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-update-mongodb-item-set-operator.png 739w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-update-mongodb-item-set-operator-300x190.png 300w" sizes="(max-width: 739px) 100vw, 739px" /></a><p id="caption-attachment-962" class="wp-caption-text">SSIS MongoDB Destination &#8211; Update MongoDB Array Item using $set update operator</p></div>
<h2>Insert MongoDB Array Item ($push / $addToSet Operator)</h2>
<p>Now lets look at how to insert new item into existing Array. Lets say we already have two orders for a customer and now we want to add new order. For this you can either use  <a href="https://docs.mongodb.com/manual/reference/operator/update/push/" target="_blank" rel="noopener">$push operator</a> or <a href="https://docs.mongodb.com/manual/reference/operator/update/addToSet/" target="_blank" rel="noopener">$addToSet operator</a>. $push operator doesn&#8217;t check for duplicate item so its little faster. If you wish to skip append if item already exists (by matching all attributes) then use $addToSet operator.</p>
<h3>Using Shell Command : Insert MongoDB Array Item (Append to array)</h3>
<p>Here is the shell command which will push new item to the array</p><pre class="crayon-plain-tag">db.MyCollection.update(
	{CustomerID:"BOLID"},
	{$push:{Orders: {"OrderID":202,"ShipCountry":"USA","ShipCity":"Atlanta" } }},
	{upsert: false,multi: false}
)</pre><p>
&nbsp;</p>
<h3>Using Shell Command : Insert MongoDB Array Item at second level</h3>
<p>Here is the shell command which will push new item to the array which is stored at second level e.g. { Orders :  [ { Items : [ insert-here ] } ] }</p><pre class="crayon-plain-tag">db.MyCollection.update(
	{CustomerID:"BOLID", "Orders.OrderID" : 202 },
	{$push:{ "Orders.$.Items" : {"ProductID":1001,"Quantity":3} } },
	{upsert: false,multi: false}
)</pre><p>
<h3>Using SSIS : Insert MongoDB Array Item at Second Level</h3>
<p>Now lets look at some example how to Insert Items inside Orders array. Since it requires two JOIN columns to perform second level array insert you may need to add metadata for join.</p>
<p>First step is create documents for update. There are atleast 4 ways you can create input documents for MongoDB Destination.</p>
<ol>
<li>You can use <a href="//zappysys.com/blog/create-mongodb-documents-ssis-json-bson-load-update-insert-upsert-collection/" target="_blank" rel="noopener">JSON generator Transform to create documents for load process</a></li>
<li>You can use <a href="//zappysys.com/blog/export-json-from-sql-server-using-ssis/" target="_blank" rel="noopener">Export JSON Task to generate input documents</a> file and then use JSON Source to Read Documents (Check Output as Document option on JSON Source to read as RAW JSON)</li>
<li>You can use JSON Source to feed direct JSON (This approach is demonstrated in the below example sceenshot)</li>
<li>You can also use SQL query to output JSON Strings along with columns used for JOIN condition<br />
<pre class="crayon-plain-tag">select CustomerID, OrderID as 'Orders.$.OrderID', DOC = '{Orders.$.Items : {ItemID: 1, Qty: 5} }'</pre>
</li>
</ol>
<p>To make it simple lets use #3 approach from above list. We will create few documents and insert New orders Items</p>
<h4>Sample Document for MongoDB Collection</h4>
<p>For testing purpose you can create MongoDB collection called test with following one document. As you see Items array is empty for both orders but once you run sample each will have 2 items.</p><pre class="crayon-plain-tag">{
    "_id" : ObjectId("58c01bee0610fea8ddda04b9"),
    "CustomerID" : "ALFKI",
    "Orders" : [ 
        {
            "OrderID" : 100,
            "Items" : [ ]
        }, 
        {
            "OrderID" : 101,
            "Items" : [ ]
        }
    ]
}</pre><p>
Now lets look at how to configure SSIS package</p>
<p>&nbsp;</p>
<h4>Step-1 : Create JSON Documents for Array Insert</h4>
<p>Lets use JSON Source like below. Use following Sample JSON</p><pre class="crayon-plain-tag">/*Insert new items into order#100*/
{CustomerID:"ALFKI","Orders.$.OrderID" : 100, Doc: "{ \"Orders.$.Items\" : {ItemID: 1, Qty: 10} }" }
{CustomerID:"ALFKI","Orders.$.OrderID" : 100, Doc: "{ \"Orders.$.Items\" : {ItemID: 2, Qty: 11} }" }

/*Insert new items into order#101*/
{CustomerID:"ALFKI","Orders.$.OrderID" : 101, Doc: "{ \"Orders.$.Items\" : {ItemID: 1, Qty: 20} }" }
{CustomerID:"ALFKI","Orders.$.OrderID" : 101, Doc: "{ \"Orders.$.Items\" : {ItemID: 2, Qty: 21} }" }</pre><p>
&nbsp;</p>
<p>&nbsp;</p>
<div id="attachment_1064" style="width: 990px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-second-level-array-update-push-insert-items-2nd.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-1064" class="size-full wp-image-1064" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-second-level-array-update-push-insert-items-2nd.png" alt="Create Sample JSON Documents for MongoDB Array Update (2nd level array)" width="980" height="744" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-second-level-array-update-push-insert-items-2nd.png 980w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-second-level-array-update-push-insert-items-2nd-300x228.png 300w" sizes="(max-width: 980px) 100vw, 980px" /></a><p id="caption-attachment-1064" class="wp-caption-text">Create Sample JSON Documents for MongoDB Array Update (2nd level array)</p></div>
<h4>Step-2 : Configure MongoDB Destination for $push operation on Second level Array</h4>
<p>Now lets connect source to Destination and configure MongoDB Destination. Select connection on first tab. Then On second tab change properties like below.</p>
<p>&nbsp;</p>
<div id="attachment_1065" style="width: 620px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-configure-second-level-array-update-push-.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-1065" class="size-full wp-image-1065" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-configure-second-level-array-update-push-.png" alt="Configure MongoDB Destination for second level array update (Insert item using $push update operator)" width="610" height="608" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-configure-second-level-array-update-push-.png 610w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-configure-second-level-array-update-push--150x150.png 150w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-configure-second-level-array-update-push--300x300.png 300w" sizes="(max-width: 610px) 100vw, 610px" /></a><p id="caption-attachment-1065" class="wp-caption-text">Configure MongoDB Destination for second level array update (Insert item using $push update operator)</p></div>
<h4>Step-3 : Add missing JOIN column for Mapping</h4>
<p>When you click on Mappings tab you will notice only root level columns are listed there for mapping but if you are JOINing based on Nested column found inside array then you have to add missing mapping column by hand like below screenshot.  In our case we Join by CustomerID and OrderID where OrderID is found in Orders array which is missing on mappings tab. So lets add it. Just make sure name new column using $ positional operator&#8230; e.g. Orders.$.OrderID  this will tell MongoDB that our OrderID column must be lookup under Array called Orders: [  ]
<div id="attachment_1066" style="width: 696px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-add-missing-columns-metadata-edit.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-1066" class="size-full wp-image-1066" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-add-missing-columns-metadata-edit.png" alt="MongoDB Destination - Add missing metadata column for JOIN " width="686" height="694" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-add-missing-columns-metadata-edit.png 686w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-add-missing-columns-metadata-edit-297x300.png 297w" sizes="(max-width: 686px) 100vw, 686px" /></a><p id="caption-attachment-1066" class="wp-caption-text">MongoDB Destination &#8211; Add missing metadata column for JOIN</p></div>
<h4>Step-4 : Map JOIN columns and Input DOCUMENT</h4>
<p>Now finally map all columns</p>
<div id="attachment_1067" style="width: 641px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-configure-mappings-second-level-array-update-push.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-1067" class="size-full wp-image-1067" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-configure-mappings-second-level-array-update-push.png" alt="SSIS MongoDB Destination - Column Mappings" width="631" height="742" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-configure-mappings-second-level-array-update-push.png 631w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-configure-mappings-second-level-array-update-push-255x300.png 255w" sizes="(max-width: 631px) 100vw, 631px" /></a><p id="caption-attachment-1067" class="wp-caption-text">SSIS MongoDB Destination &#8211; Column Mappings</p></div>
<h3>Using SSIS : Insert MongoDB Array Item (Append to array)</h3>
<p>Now lets look at how to perform same operation to insert array item in SSIS using $push operator. In this case we will do little different than Update Item example ($set operator). First we have not included CustomerID as part of Input columns and we mapped it on Mapping Screen rather than supplying columns names in ColumnsForLookup property (On Component Properties Tab of Destination UI). If you are using JSON Generator Transform to generate your JSON then you have option to Hide/Include certain columns part of your flow. Check Include column to downstream option if you want to use for JOIN column.</p>
<p>Set following settings</p>
<ul>
<li>Set LoadOptions as below<br />
<strong>op=$push;multi=true</strong></li>
<li>Set Operation=Update</li>
<li>Leave ColumnsForLookup as empty</li>
<li>On the mappings tab map __DOCUMENT__ and CustomerID in the Target. If you don&#8217;t see CustomerID column in the mapping create atleast one sample doc in MongoDB Collection so metadata is detected.</li>
</ul>
<p>Download Sample for more detail.</p>
<div id="attachment_966" style="width: 958px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-json-source-generate-json-for-mongodb-array-item-insert.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-966" class="size-full wp-image-966" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-json-source-generate-json-for-mongodb-array-item-insert.png" alt="SSIS JSON Source - generate JSON for MongoDB Array Insert" width="948" height="516" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-json-source-generate-json-for-mongodb-array-item-insert.png 948w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-json-source-generate-json-for-mongodb-array-item-insert-300x163.png 300w" sizes="(max-width: 948px) 100vw, 948px" /></a><p id="caption-attachment-966" class="wp-caption-text">SSIS JSON Source &#8211; generate JSON for MongoDB Array Insert</p></div>
<div id="attachment_968" style="width: 684px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-insert-array-item-push-addtoset-operator.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-968" class="size-full wp-image-968" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-insert-array-item-push-addtoset-operator.png" alt="SSIS MongoDB Destination - Insert MongoDB Array Item (Use $push, or $addToSet operator)" width="674" height="436" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-insert-array-item-push-addtoset-operator.png 674w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-destination-insert-array-item-push-addtoset-operator-300x194.png 300w" sizes="(max-width: 674px) 100vw, 674px" /></a><p id="caption-attachment-968" class="wp-caption-text">SSIS MongoDB Destination &#8211; Insert MongoDB Array Item (Use $push, or $addToSet operator)</p></div>
<h2>Delete MongoDB Array Item ($pull operator)</h2>
<p>If you wish to remove array item then you can use <a href="https://docs.mongodb.com/manual/reference/operator/update/pull/" target="_blank" rel="noopener">$pull operator</a>. Only difference is rather than specifying two conditions in first argument&#8230; you just specify JOIN columns without array column (i.e. OrderID). To specify Array item condition you have to set inside $pull : { &#8230; }</p>
<h3>Using Shell Command for MongoDB Delete Array Item (Remove by condition)</h3>
<p>Below example shows how to remove OrderID=201 from Orders array for CustomerID=BOLID.</p><pre class="crayon-plain-tag">db.MyCollection.update(
	{CustomerID:"BOLID"},
	{$pull:{Orders: {"OrderID":201} }},
	{upsert: false,multi: false}
)</pre><p>
&nbsp;</p>
<h3>Using SSIS for MongoDB Delete Array Item</h3>
<p>Now lets look at how to implement Delete logic for MongoDB Array Item in SSIS. As you see in below screenshots You have to modify following things</p>
<ul>
<li>Set ColumnsForLookup property to CustomerID (no need to add OrderID here because its part of input document)</li>
<li>Set LoadOptions property to op=none;multi=false. op=none means we are supplying Update operator part of input document.</li>
</ul>
<p>Assume you have doc like below in MongoDB  and you like to remove Order#101 from array</p><pre class="crayon-plain-tag">{
    "_id" : ObjectId("58c01bee0610fea8ddda04b9"),
    "ParentID" : 1,
    "Orders" : [ 
        100, 
        101, 
        102
    ]
}</pre><p>
For this supply 2 columns from upstream<br />
col1  = ParentID<br />
col2  = DOCUMENT</p>
<p>Document column should look like below<br />
{Orders: 101}</p>
<ol>
<li>On MongoDB destination change LoadOptions property to  op=$pull;multi=true</li>
<li>Change Operation to Update</li>
<li>Map ParentID and DOCUMENT columns on Mapping screen</li>
<li>Run the package &#8230; It will remove Order# 101 from array</li>
</ol>
<h2>Array Upsert &#8211; Update / Insert using Custom JOIN condition (such as $ne )</h2>
<p>If you like to perform Upsert Operation on MongoDB Array Items then refer to below blog post.</p>
<blockquote class="wp-embedded-content" data-secret="kVibThe8Ux"><p><a href="https://zappysys.com/blog/update-insert-upsert-mongodb-array-items-ssis/">Update or Insert &#8211; Upsert MongoDB Array Items using SSIS</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" src="https://zappysys.com/blog/update-insert-upsert-mongodb-array-items-ssis/embed/#?secret=kVibThe8Ux" data-secret="kVibThe8Ux" width="600" height="338" title="&#8220;Update or Insert &#8211; Upsert MongoDB Array Items using SSIS&#8221; &#8212; ZappySys Blog" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>&nbsp;</p>
<h2>Conclusion</h2>
<p>MongoDB integration can be challenging if you are new to NoSQL world. If you are using SSIS as your primary ETL tool then not to worry because <a href="//zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">SSIS PowerPack</a> can give super power needed to complete your project on time with drag and drop high performance connectors.</p>
<p>Keywords: mongodb update array item | mongodb update array elements | mongodb update array documents | MongoDB $ operator | MongoDB update sub document items | MongoDB CRUD operations | MongoDB Bulk Updates | MongoDB bulk updates to array items</p>
<p>The post <a href="https://zappysys.com/blog/update-mongodb-array-items-using-ssis/">Update MongoDB Array Items using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to parse MongoDB Date time in SSIS</title>
		<link>https://zappysys.com/blog/parse-mongodb-date-time-in-ssis-custom-format/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Wed, 18 Jan 2017 14:57:50 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB Source]]></category>
		<category><![CDATA[ISODate]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[SSIS PowerPack]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=946</guid>

					<description><![CDATA[<p>Introduction In our previous post we explained how to read/load MongoDB data in SSIS. This post covers specifically how to parse MongoDB date time stored inside your MongoDB documents. By default any well known date formats (e.g. ISO date) will be parsed as valid datetime (e.g. DT_DBTIMESTAMP) when you use SSIS MongoDB Source. But if you [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/parse-mongodb-date-time-in-ssis-custom-format/">How to parse MongoDB Date time in SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><img loading="lazy" decoding="async" class="size-full wp-image-2115 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png" alt="" width="88" height="88" />In our previous post we explained <a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/" target="_blank" rel="noopener">how to read/load MongoDB data in SSIS</a>. This post covers specifically <strong>how to parse MongoDB date time</strong> stored inside your MongoDB documents. By default any well known date formats (e.g. ISO date) will be parsed as valid datetime (e.g. DT_DBTIMESTAMP) when you use <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">SSIS MongoDB Source</a>. But if you have date stored as other format (e.g. MM-dd-yyyy) then system will not parse as string unless you specify custom date format on JSON Datetime tab. If you want to learn How to query Date in MongoDB then <a href="https://zappysys.com/blog/how-to-query-mongodb-by-date-or-isodate/" target="_blank" rel="noopener">read this article</a></p>
<h2>Parse MongoDB Date time using SSIS MongoDB Source</h2>
<p>Perform the following steps to enable custom date format parsing for date not stored as ISODate in MongoDB. Below steps assume you have Downloaded and Installed <a href="//zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">SSIS PowerPack from Here</a></p>
<p>NOTE: Below steps not necessary if your date is stored as <strong>ISODate</strong> in MongoDB&#8230;. e.g.  { &#8220;OrderDate&#8221; : ISODate(&#8220;2015-12-31T00:00:00Z&#8221;)  }</p>
<ol>
<li>Open MongoDB Source. Change Mode to Query Mode</li>
<li>Check Enable JSON option. You don&#8217;t have to type filter (its optional)</li>
<li>Goto JSON Options and then Datetime options Tab</li>
<li>Enter custom date format (The way your date stored in MongoDB)</li>
</ol>
<p>Now go to columns and click refresh columns. It will detect column as DT_DBTIMESTAMP (e.g. date/time)</p>
<p>&nbsp;</p>
<div id="attachment_950" style="width: 971px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-parse-mongodb-date-time-custom-format.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-950" class="size-full wp-image-950" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-parse-mongodb-date-time-custom-format.png" alt="SSIS MongoDB Source- Date Time Options ( Parse MongoDB Date)" width="961" height="496" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-parse-mongodb-date-time-custom-format.png 961w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-parse-mongodb-date-time-custom-format-300x155.png 300w" sizes="(max-width: 961px) 100vw, 961px" /></a><p id="caption-attachment-950" class="wp-caption-text">SSIS MongoDB Source- Date Time Options ( Parse MongoDB Date)</p></div>
<div id="attachment_949" style="width: 546px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-query-date-time-fields.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-949" class="size-full wp-image-949" src="//zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-query-date-time-fields.png" alt="SSIS MongoDB Source - Query and Parse MongoDB Date with Custom format" width="536" height="291" srcset="https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-query-date-time-fields.png 536w, https://zappysys.com/blog/wp-content/uploads/2017/01/ssis-mongodb-query-date-time-fields-300x163.png 300w" sizes="(max-width: 536px) 100vw, 536px" /></a><p id="caption-attachment-949" class="wp-caption-text">SSIS MongoDB Source &#8211; Query and Parse MongoDB Date with Custom format</p></div>
<p>The post <a href="https://zappysys.com/blog/parse-mongodb-date-time-in-ssis-custom-format/">How to parse MongoDB Date time in SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to extract multiple arrays from MongoDB using SSIS</title>
		<link>https://zappysys.com/blog/how-to-extract-multiple-arrays-from-mongodb-using-ssis/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Thu, 12 Jan 2017 18:30:53 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB Source]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[ssis json parser transform]]></category>
		<category><![CDATA[ssis multicast]]></category>
		<category><![CDATA[SSIS PowerPack]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=940</guid>

					<description><![CDATA[<p>Since MongoDB Source supports only one output you cannot select two different hierarchies as your filter criteria. However solution is easy. You can perform following steps to achieve similar result without fetching data twice with multiple sources. Same steps described below can be applied for JSON Source (read more here) &#160; Steps &#8211; Extract multiple [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/how-to-extract-multiple-arrays-from-mongodb-using-ssis/">How to extract multiple arrays from MongoDB using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png"><img loading="lazy" decoding="async" class="size-full wp-image-2115 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png" alt="" width="88" height="88" /></a>Since <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">MongoDB Source</a> supports only one output you cannot select two different hierarchies as your filter criteria. However solution is easy. You can perform following steps to achieve similar result without fetching data twice with multiple sources. Same steps described below can be applied for <a href="//zappysys.com/products/ssis-powerpack/ssis-json-file-source/" target="_blank" rel="noopener">JSON Source</a> (read <a href="https://zappysys.com/blog/extract-read-multiple-arrays-from-json-data-file-rest-api-response/" target="_blank" rel="noopener">more here</a>)</p>
<p>&nbsp;</p>
<h2>Steps &#8211; Extract multiple arrays from MongoDB</h2>
<ol>
<li>Extract data using MongoDB source (Select output mode as Raw Document)</li>
<li>Connect MongoDB Source to Multicast Transform</li>
<li>Connect multi cast output to <a href="//zappysys.com/products/ssis-powerpack/ssis-json-parser-transform/" target="_blank" rel="noopener">JSON Parser Transform</a> which will take upstream raw JSON doc and convert to Flat table output just like MongoDB source. On Json Parser specify filter e.g. $.doc.<strong>Array1</strong>[*]</li>
<li>Connect Json Parser Transform output to desired target e.g. sql server/flat file.</li>
<li>Repeat step #3,4,5 for  as many outputs you need with different filter settings (e.g. $.doc.<strong>Array2</strong>[*]).</li>
</ol>
<p>Here is more info about JSON Parser Transform (This is new Transform added in v2.2)</p>
<p><a href="//zappysys.com/products/ssis-powerpack/ssis-json-parser-transform/">//zappysys.com/products/ssis-powerpack/ssis-json-parser-transform/</a></p>
<h2>Video Tutorial &#8211; Step By Step &#8211; How to read multiple MongoDB arrays</h2>
<p>Below video tutorial demonstrates following things</p>
<p>* How to execute MongoDB Shell commands in SSIS (e.g. create Collection)<br />
* How to read data from multiple arrays from MongoDB document (i.e. Orders, Products)<br />
* Save result into two SQL Server tables</p>
<a href="https://zappysys.com/blog/how-to-extract-multiple-arrays-from-mongodb-using-ssis/"><img decoding="async" src="https://zappysys.com/blog/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FKtXRxlhBF5M%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p>
<p>&nbsp;</p>
<p>The post <a href="https://zappysys.com/blog/how-to-extract-multiple-arrays-from-mongodb-using-ssis/">How to extract multiple arrays from MongoDB using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to call MongoDB JavaScript using SSIS</title>
		<link>https://zappysys.com/blog/call-mongodb-javascript-using-ssis-execute-sql-task/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Fri, 14 Oct 2016 17:31:25 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB ExecuteSQL]]></category>
		<category><![CDATA[eval]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[runcommand]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[SSIS PowerPack]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=811</guid>

					<description><![CDATA[<p>Introduction SSIS PowerPack comes with great features for MongoDB Integration Scenarios but in this post we will focus on how to call MongoDB Javascript (Server side) using SSIS. For this purpose we will use SSIS MongoDB Execute SQL Task This powerful task not only easy to use but it supports calling any valid MongoDB commands [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/call-mongodb-javascript-using-ssis-execute-sql-task/">How to call MongoDB JavaScript using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><img loading="lazy" decoding="async" class="size-full wp-image-2115 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png" alt="" width="88" height="88" /><a href="//zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">SSIS PowerPack</a> comes with great features for <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-integration-pack/" target="_blank" rel="noopener">MongoDB Integration Scenarios</a> but in this post we will focus on how to <em>call MongoDB Javascript</em> (Server side) using SSIS. For this purpose we will use <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/" target="_blank" rel="noopener">SSIS MongoDB Execute SQL Task</a></p>
<p>This powerful task not only easy to use but it supports calling any valid MongoDB commands including <em>Server side Java Script</em>.</p>
<div class="su-note"  style="border-color:#e5e54c;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#FFFF66;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><strong> NOTE:</strong> ZappySys could not support $eval function, If you&#8217;ve installed MongoDB version higher than 3.0 version as MongoDB have removed support for the $eval function from version 4.2.<br />
If you still want to use $eval function then you need to downgrade MongoDB to a lower than 4.2 version.<br />
Please Refer to <a href="https://docs.mongodb.com/manual/release-notes/4.2-compatibility/#remove-support-for-the-eval-command" target="_blank" rel="noopener">MongoDB Release Notes</a> for reference. </div></div>
<h2>How to call MongoDB JavaScript &#8211; Example</h2>
<p>To call various MongoDB shell commands or <em>execute JavaScript in MongoDB</em> using SSIS you have Download and Install <a href="//zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">SSIS PowerPack</a> . Once its installed perform following steps.</p>
<ol>
<li>From SSIS Toolbox drag ZS MongoDB ExecuteSQL Task</li>
<li>Click New to create new MongoDB connection manager</li>
<li>Once connection is configured click Test and OK to save</li>
<li>Now you can use {{Examples}} dropdown to see possible scenarios with MongoDB ExecuteSQL task</li>
<li>Below is sample script to call Aggregate command</li>
</ol>
<p><strong> NOTE:</strong> See how we returned command output using <strong>toArray()</strong> Javascript function at the end? This will give us all records in clean JSON Array format which can be consumed easily using <a href="//zappysys.com/products/ssis-powerpack/ssis-json-file-source/" target="_blank" rel="noopener">SSIS JSON Source.</a> If you don&#8217;t use toArray then you may get Cursor with only first batch.</p>
<div class="su-note"  style="border-color:#e5e54c;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#FFFF66;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">ZappySys MongoDB Shell command syntax (i.e. JSON) supports both double quotes and single quotes around the property name or value (i.e. your script). If you wrap your code with single quote then do not use single quote inside script block. </div></div>
<pre class="crayon-plain-tag">{
scope: 'database',
db: '{{User::varDB}}',
command: 'eval',
args: 
 { 
  code : 'function()
  {
   var varState="GA"
   return db.zipcodes.aggregate( 
   [
   {$match : { state: varState } },
   {$group : {_id :  "$state", TotalPopulation: { $sum: "$pop" }}},
   {$match: { TotalPopulation: { $gt: 25 } } },
   {$project : { StateAbbr: "$_id" , _id: 0, TotalPopulation:1 } },
   {$sort : {TotalPopulation : -1}}
   ]).toArray(); 
  }'
 }
}</pre>
<h2>Call MongoDB single line commands</h2>
<p>If you wish to call commands which are single line only then you may use below code which is simpler than previous example. Notice it doesn&#8217;t require function() keyword like previous one. Make sure your code has to be in single line or try to use \r\n for new line</p><pre class="crayon-plain-tag">{
 scope: 'database',
 command: 'eval',
 args: { code: 'db.hostInfo()' } 
}</pre><p>
<h2>Permissions needed to call JavaScript</h2>
<p>Calling eval command requires special permission so make sure you setup permission so MongoDB user can call db.runCommand ( {eval command} ). Here is more information about <a href="https://docs.mongodb.com/manual/reference/command/eval/" target="_blank" rel="noopener">calling eval command in MongoDB</a>.</p>
<h2>Save Result JSON of MongoDB command into SSIS variable</h2>
<p>If you want to save MongoDB command output as JSON into SSIS Variable then set Result mode = RawResult</p>
<div id="attachment_816" style="width: 610px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/10/call-mongodb-javascript-ssis-execute-sql-task-save-json-raw-result.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-816" class="wp-image-816" src="//zappysys.com/blog/wp-content/uploads/2016/10/call-mongodb-javascript-ssis-execute-sql-task-save-json-raw-result.png" alt="Call MongoDB JavaScript in SSIS Using Execute SQL Task - Aggregate Command Example - Save raw JSON output into SSIS variable" width="600" height="554" srcset="https://zappysys.com/blog/wp-content/uploads/2016/10/call-mongodb-javascript-ssis-execute-sql-task-save-json-raw-result.png 794w, https://zappysys.com/blog/wp-content/uploads/2016/10/call-mongodb-javascript-ssis-execute-sql-task-save-json-raw-result-300x277.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><p id="caption-attachment-816" class="wp-caption-text">Call MongoDB JavaScript in SSIS Using Execute SQL Task &#8211; Aggregate Command Example &#8211; Save raw JSON output into SSIS variable</p></div>
<h2>How to use MongoDB Eval command to call runCommand function</h2>
<p>Now lets look at how to call some admin functions using runCommand function. In below example we setting Global Timeout setting for Cursor (This helps to avoid timeout for long running cursor query)</p><pre class="crayon-plain-tag">{
 scope: 'database',
 command: 'eval',
 args: { code: "db.getSiblingDB('admin').runCommand( { setParameter: 1, cursorTimeoutMillis: 400000 } )" } 
}</pre><p>
<div id="attachment_1169" style="width: 1089px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/10/ssis-mongodb-setparameter-cursor-timeout.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-1169" class="size-full wp-image-1169" src="//zappysys.com/blog/wp-content/uploads/2016/10/ssis-mongodb-setparameter-cursor-timeout.png" alt="Setting MongoDB Cursor Timeout ( set cursorTimeoutMillis parameter )" width="1079" height="685" srcset="https://zappysys.com/blog/wp-content/uploads/2016/10/ssis-mongodb-setparameter-cursor-timeout.png 1079w, https://zappysys.com/blog/wp-content/uploads/2016/10/ssis-mongodb-setparameter-cursor-timeout-300x190.png 300w, https://zappysys.com/blog/wp-content/uploads/2016/10/ssis-mongodb-setparameter-cursor-timeout-1024x650.png 1024w" sizes="(max-width: 1079px) 100vw, 1079px" /></a><p id="caption-attachment-1169" class="wp-caption-text">Setting MongoDB Cursor Timeout ( set cursorTimeoutMillis parameter )</p></div>
<p>&nbsp;</p>
<h2>Save Result of MongoDB command into SSIS variable as ADO.net Table</h2>
<p>If you want to use ForEach Loop to iterate through certain records from MongoDB result then set Result mode = FullResult this will save result as ADO.net table rather than JSON. Example : Get all collections and loop through them in SSIS using ForEachLoop Task?</p>
<div id="attachment_817" style="width: 610px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/10/call-mongodb-javascript-ssis-execute-sql-task-save-full-result.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-817" class="wp-image-817" src="//zappysys.com/blog/wp-content/uploads/2016/10/call-mongodb-javascript-ssis-execute-sql-task-save-full-result.png" alt="Call MongoDB JavaScript in SSIS - Aggregate Command - Save JSON output as ADO.net Table - Loop Through ForEachLoop" width="600" height="547" srcset="https://zappysys.com/blog/wp-content/uploads/2016/10/call-mongodb-javascript-ssis-execute-sql-task-save-full-result.png 798w, https://zappysys.com/blog/wp-content/uploads/2016/10/call-mongodb-javascript-ssis-execute-sql-task-save-full-result-300x274.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><p id="caption-attachment-817" class="wp-caption-text">Call MongoDB JavaScript in SSIS &#8211; Aggregate Command &#8211; Save JSON output as ADO.net Table &#8211; Loop Through ForEachLoop</p></div>
<h2>Conclusion</h2>
<p>MongoDB is the most popular NoSQL Database engine but integrating that into SSIS can be challenging without right tools. ZappySys SSIS PowerPack comes with many <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-integration-pack/" target="_blank" rel="noopener">MongoDB Tasks/Components for SSIS</a>.</p>
<p>The post <a href="https://zappysys.com/blog/call-mongodb-javascript-using-ssis-execute-sql-task/">How to call MongoDB JavaScript using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to create MongoDB documents (JSON, BSON) for loading in SSIS</title>
		<link>https://zappysys.com/blog/create-mongodb-documents-ssis-json-bson-load-update-insert-upsert-collection/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Tue, 30 Aug 2016 15:07:22 +0000</pubDate>
				<category><![CDATA[SSIS JSON Generator Transform]]></category>
		<category><![CDATA[BSON]]></category>
		<category><![CDATA[ISODate]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[SSIS MongoDB Destination]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=742</guid>

					<description><![CDATA[<p>Introduction In our previous article, we discussed how to load data into MongoDB (Insert, Update, or Upsert Mode) with various options. In this post, we will focus on creating a MongoDB Document for the load process. We will see how to produce BSON (MongoDB-specific JSON that may include functions such as ObjectID and ISODate). This article assumes you have [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/create-mongodb-documents-ssis-json-bson-load-update-insert-upsert-collection/">How to create MongoDB documents (JSON, BSON) for loading in SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png"><img loading="lazy" decoding="async" class="size-full wp-image-2115 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png" alt="" width="88" height="88" /></a><span style="box-sizing: border-box; margin: 0px; padding: 0px;">In our previous article, we discussed how to <a target="_blank" rel="noopener">load data into MongoDB (Insert, Update, or Upsert Mode)</a> with various options. </span>In this post, we will focus on creating a MongoDB Document for the load process. We will see how to produce BSON (MongoDB-specific JSON<span style="box-sizing: border-box; margin: 0px; padding: 0px;"> that may include functions such as <em>ObjectID and</em></span> <em>ISODate</em>).</p>
<p>This article assumes you have installed <a href="//zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">SSIS PowerPack</a> and watched the introduction videos of <a href="//zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/" target="_blank" rel="noopener">SSIS JSON Generator Transform</a> and <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/" target="_blank" rel="noopener">MongoDB Destination Connector</a></p>
<h2>Create MongoDB document Example (Produce JSON, BSON for Load)</h2>
<p>Here is the screenshot, which shows how to fetch SQL Server data &gt; create a MongoDB document in JSON / BSON format, and load it into a MongoDB collection</p>
<p>The high-level steps we performed are</p>
<ol>
<li>Used OLEDB Source to fetch data from SQL Server. Used a query like below<br />
<pre class="crayon-plain-tag">select CustomerID, 'ISODate("' + convert(varchar(30),getdate(),126) + '")' as DOB from Customers</pre>
In the above query, you will notice that we are building some BSON fragments, which will be treated as raw values in the JSON generator. Also, we are using the convert function from SQL Server to produce an ISO date format (Style=126 will produce an ISO date)</li>
<li>Used the <a href="//zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/" target="_blank" rel="noopener">SSIS JSON Generator Transform</a> to produce a JSON document for each customer. Define a custom layout using the drag-and-drop interface. You can control how many documents you want to output using settings on Transform (Single document for all input rows or one document per row in the Main dataset)</li>
<li>Load JSON documents coming from upstream into MongoDB using the <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/" target="_blank" rel="noopener">SSIS MongoDB Destination Connector</a>. We changed Action=Upsert and set ColumnsForLookup to CustomerID (Consider this as Primary Key or your Join Column to find existing document)</li>
<li>On Target, we mapped __DOCUMENT__ rather than individual columns, so that we can load the full document.
<div id="attachment_11582" style="width: 775px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2016/08/Sample-SSIS-Package-Create-MongoDB-Document-in-BSON-format-JSON-with-functions.-Update-or-Insert-Mode.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-11582" class="size-full wp-image-11582" src="https://zappysys.com/blog/wp-content/uploads/2016/08/Sample-SSIS-Package-Create-MongoDB-Document-in-BSON-format-JSON-with-functions.-Update-or-Insert-Mode.png" alt="" width="765" height="625" srcset="https://zappysys.com/blog/wp-content/uploads/2016/08/Sample-SSIS-Package-Create-MongoDB-Document-in-BSON-format-JSON-with-functions.-Update-or-Insert-Mode.png 765w, https://zappysys.com/blog/wp-content/uploads/2016/08/Sample-SSIS-Package-Create-MongoDB-Document-in-BSON-format-JSON-with-functions.-Update-or-Insert-Mode-300x245.png 300w" sizes="(max-width: 765px) 100vw, 765px" /></a><p id="caption-attachment-11582" class="wp-caption-text">Sample SSIS Package &#8211; Create MongoDB Document in BSON format (JSON with functions). Update or Insert Mode</p></div></li>
</ol>
<h2>Configure JSON Generator Transform &#8211; Create JSON Document</h2>
<p>If you want to learn how to configure the <a target="_blank" rel="noopener">SSIS JSON Generator Transform,</a> then watch the video <a target="_blank" rel="noopener">here.</a> Important thing to remember in the configuration is to check the <strong>Treat value of this column as Raw JSON</strong></p>
<div id="attachment_11581" style="width: 938px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2016/08/Create-MongoDB-Document-in-JSON-or-BSON-format-Load-into-Collection-Upsert-Update-or-Insert.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-11581" class="size-full wp-image-11581" src="https://zappysys.com/blog/wp-content/uploads/2016/08/Create-MongoDB-Document-in-JSON-or-BSON-format-Load-into-Collection-Upsert-Update-or-Insert.png" alt="" width="928" height="652" srcset="https://zappysys.com/blog/wp-content/uploads/2016/08/Create-MongoDB-Document-in-JSON-or-BSON-format-Load-into-Collection-Upsert-Update-or-Insert.png 928w, https://zappysys.com/blog/wp-content/uploads/2016/08/Create-MongoDB-Document-in-JSON-or-BSON-format-Load-into-Collection-Upsert-Update-or-Insert-300x211.png 300w, https://zappysys.com/blog/wp-content/uploads/2016/08/Create-MongoDB-Document-in-JSON-or-BSON-format-Load-into-Collection-Upsert-Update-or-Insert-768x540.png 768w" sizes="(max-width: 928px) 100vw, 928px" /></a><p id="caption-attachment-11581" class="wp-caption-text">Create MongoDB Document in JSON or BSON format &#8211; Load into Collection (Upsert &#8211; Update or Insert)</p></div>
<h2>Configure MongoDB Destination &#8211; For Upsert (Update or Insert Mode)</h2>
<p><span style="box-sizing: border-box; margin: 0px; padding: 0px;">By default, the <a target="_blank" rel="noopener">SSIS MongoDB Destination Connector</a> performs an insert, but if you want to perform an Upsert (i.e., insert if not found, else update), you have to change a few settings.</span></p>
<ol>
<li>Change Operation to UpdateOrInsert</li>
<li>Set ColumnsForLookup (e.g., in our case, it was just one CustomerID). If you have multiple columns for join, then use a comma-separated list (e.g., City, State, Zip)</li>
<li>If you want to affect various documents if more than one match is found for the join criteria, then use multi=true as shown in the screenshot below (see LoadOptions )
<div id="attachment_11580" style="width: 1003px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2016/08/Configure-SSIS-MongoDB-destination-for-Upsert-operation.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-11580" class="size-full wp-image-11580" src="https://zappysys.com/blog/wp-content/uploads/2016/08/Configure-SSIS-MongoDB-destination-for-Upsert-operation.png" alt="" width="993" height="528" srcset="https://zappysys.com/blog/wp-content/uploads/2016/08/Configure-SSIS-MongoDB-destination-for-Upsert-operation.png 993w, https://zappysys.com/blog/wp-content/uploads/2016/08/Configure-SSIS-MongoDB-destination-for-Upsert-operation-300x160.png 300w, https://zappysys.com/blog/wp-content/uploads/2016/08/Configure-SSIS-MongoDB-destination-for-Upsert-operation-768x408.png 768w" sizes="(max-width: 993px) 100vw, 993px" /></a><p id="caption-attachment-11580" class="wp-caption-text">Configure the SSIS MongoDB destination for the Upsert operation</p></div></li>
</ol>
<div class="mceTemp"></div>
<h2>Conclusion</h2>
<p>In this post, you have seen how easy it is to create MongoDB Documents in JSON / BSON format and load them into a MongoDB collection using <a target="_blank" rel="noopener">ZappySys SSIS PowerPack</a>. This innovative drag-and-drop approach can simplify the entire ETL process if you are in a time crunch and don&#8217;t know scripting languages.</p>
<p>The post <a href="https://zappysys.com/blog/create-mongodb-documents-ssis-json-bson-load-update-insert-upsert-collection/">How to create MongoDB documents (JSON, BSON) for loading in SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to write MongoDB Aggregation Queries in SSIS (Group By)</title>
		<link>https://zappysys.com/blog/aggregate-mongodb-data-using-group-by-query-in-ssis/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Wed, 17 Aug 2016 15:52:17 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB Source]]></category>
		<category><![CDATA[MongoDB]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=736</guid>

					<description><![CDATA[<p>Introduction In this post you will learn how to write flexible MongoDB Aggregation Queries in SSIS (i.e. Group By Query) using SSIS MongoDB Source Component. MongoDB provides powerful Aggregation Pipeline Engine which is conceptually same as writing Group By queries in traditional SQL world but its not exactly same. SSIS MongoDB Source returns nested MongoDB JSON [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/aggregate-mongodb-data-using-group-by-query-in-ssis/">How to write MongoDB Aggregation Queries in SSIS (Group By)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><img loading="lazy" decoding="async" class="size-full wp-image-2115 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png" alt="" width="88" height="88" />In this post you will learn how to write flexible <strong>MongoDB Aggregation Queries in SSIS</strong> (i.e. Group By Query) using <a href="https://zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">SSIS MongoDB Source Component</a>. MongoDB provides powerful Aggregation Pipeline Engine which is conceptually same as writing Group By queries in traditional SQL world but its not exactly same. <a href="https://zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">SSIS MongoDB Source</a> returns nested MongoDB JSON documents into flat looking table with rows and column (denormalized data).</p>
<p>If you want to learn <a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/" target="_blank" rel="noopener">how to write data to MongoDB (Insert, Update, Delete, Upsert) then click here</a>. If you want learn <a href="https://zappysys.com/blog/read-mongodb-data-from-array-extract-nested-sub-documents/" target="_blank" rel="noopener">how to read data from MongoDB then click here</a>.</p>
<p>So let&#8217;s explore concepts of <a href="https://docs.mongodb.com/manual/core/aggregation-pipeline/" target="_blank" rel="noopener">MongoDB Aggregation Pipeline</a> and see some MongoDB query examples for SSIS use case.</p>
<div class="content_block" id="custom_post_widget-2523"><h2><span id="Prerequisites">Prerequisites</span></h2>
Before we perform the steps listed in this article, you will need to make sure the following prerequisites are met:
<ol style="margin-left: 1.5em;">
 	<li><abbr title="SQL Server Integration Services">SSIS</abbr> designer installed. Sometimes it is referred to as <abbr title="Business Intelligence Development Studio">BIDS</abbr> or <abbr title="SQL Server Data Tools">SSDT</abbr> (<a href="https://docs.microsoft.com/en-us/sql/ssdt/download-sql-server-data-tools-ssdt" target="_blank" rel="noopener">download it from the Microsoft site</a>).</li>
 	<li>Basic knowledge of SSIS package development using <em>Microsoft SQL Server Integration Services</em>.</li>
 	<li>Make sure <span style="text-decoration: underline;"><a href="https://zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">ZappySys SSIS PowerPack</a></span> is installed (<a href="https://zappysys.com/products/ssis-powerpack/download/" target="_blank" rel="noopener">download it</a>, if you haven't already).</li>
 	<li>(<em>Optional step</em>)<em>.</em> <a href="https://zappysys.zendesk.com/hc/en-us/articles/360035974593" target="_blank" rel="noopener">Read this article</a>, if you are planning to deploy packages to a server and schedule their execution later.</li>
</ol></div>
<h2>SSIS MongoDB Source Introduction</h2>
<p><a href="https://zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">SSIS MongoDB Source</a> supports three modes to read data from MongoDB collection. Each mode also supports <a href="https://zappysys.com/blog/read-mongodb-data-from-array-extract-nested-sub-documents/" target="_blank" rel="noopener">JSONPath Expression to extract nested array</a>.</p>
<ol>
<li>Table Mode</li>
<li>SQL Query Mode</li>
<li>JSON Query Mode (Native)</li>
</ol>
<p>To read more about supported SQL Syntax read <a href="https://zappysys.com/onlinehelp/ssis-powerpack/scr/mongodb-source.htm" target="_blank" rel="noopener">help file here</a>.</p>
<h2>Using SSIS MongoDB Source to Query Data (Aggregation)</h2>
<p>Now lets look at how to use <a href="https://zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">SSIS MongoDB Source</a> to query MongoDB data using Aggregation Engine.</p>
<h3>MongoDB Aggregation Pipeline Syntax in SSIS</h3>
<p><a href="https://zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">SSIS MongoDB Source</a> support all pipeline commands to write aggregation queries but its slighly different syntax than shell command so your SHell Query won&#8217;t work directly but you can copy some part of your Shell query. Check below Syntax.</p>
<p><strong>MongoDB Native Query Syntax (Shell Command) for Aggregation:</strong></p><pre class="crayon-plain-tag">db.YourCollectionName.aggregate(
[
[ &lt;pipeline-stage1&gt;]
[,&lt;pipeline-stage2&gt;]
...
...
[,&lt;pipeline-stageN&gt;]
]
)</pre><p>
<strong>SSIS MongoDB Source Query Syntax for Aggregation:</strong><code><br />
</code></p><pre class="crayon-plain-tag">{Table:YourTableName ,Method:aggregate [,MaxRows: N] [,AllowDiskUse:true] [,AllowCursor:true] [,Timeout:#####] }
{
pipeline: [
[ &lt;pipeline-stage1&gt;]
[,&lt;pipeline-stage2&gt;]
...
...
[,&lt;pipeline-stageN&gt;]
]
}</pre><p>
&nbsp;</p>
<h2>Example Aggregation Queries (SQL to SSIS Mapping)</h2>
<p>Assume that we want to write following SQL Query using <a href="https://zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">SSIS MongoDB Source</a> or using MongoDB Shell</p><pre class="crayon-plain-tag">SELECT State as StateAbbr,SUM(population) as TotalPopulation 
FROM ZipCodes 
WHERE status='Active' 
HAVING SUM(population) &amp;gt; 25
Order By TotalPopulation DESC</pre><p>
Above SQL Query can be translated to below JSON Query which can be used in SSIS MongoDB Source. As we noted before Below syntax is not same as Shell command so it will only run in SSIS MongoDB Source.</p><pre class="crayon-plain-tag">{Table: ZipCodes,Method: aggregate}
{
  pipeline: 
  [
    {$match : { status: &quot;A&quot; } } ,
    {$group : {_id :  &quot;$state&quot;, TotalPopulation: { $sum: &quot;$pop&quot; }}},
    {$match: { TotalPopulation: { $gt: 25 } } },
    {$project : { StateAbbr: &quot;$_id&quot; , _id: 0, TotalPopulation:1 } },
    {$sort : {TotalPopulation : -1}}
  ]
}</pre><p>
So as you saw in above query various clause of SELECT queries are defined as pipeline stages. You can add any possible stages in different order. Based on their order it will be applied so order of stage is very important.  For more information about various <a href="https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/" target="_blank" rel="noopener">pipeline stages click here</a>. Below is high level translation of SQL Query to MongoDB Aggregation Query.</p>
<div style="width: 616px" class="wp-caption alignnone"><a class="figureimage" href="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/mongodb-source/ssis-mongodb-group-by-query-aggregation-framework.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" src="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/mongodb-source/ssis-mongodb-group-by-query-aggregation-framework.png" alt="SSIS MongoDB Source - Example of MongoDB Group By Query (Aggregation Framework - Pipeline)" width="606" height="555" /></a><p class="wp-caption-text">SSIS MongoDB Source &#8211; Example of MongoDB Group By Query (Aggregation Framework &#8211; Pipeline)</p></div>
<p><strong>SQL to MongoDB Aggregation Mapping</strong></p>
<div class="su-table su-table-alternate">
<table>
<thead>
<tr>
<th>SQL Clause</th>
<th>Mongo Pipeline Stage</th>
</tr>
</thead>
<tbody>
<tr>
<td>SELECT</td>
<td><a href="https://docs.mongodb.com/manual/reference/operator/aggregation/project/" target="_blank" rel="noopener">$project</a></td>
</tr>
<tr>
<td>WHERE</td>
<td><a href="https://docs.mongodb.com/manual/reference/operator/aggregation/match/" target="_blank" rel="noopener">$match</a></td>
</tr>
<tr>
<td>GROUP BY</td>
<td><a href="https://docs.mongodb.com/manual/reference/operator/aggregation/group/" target="_blank" rel="noopener">$group</a></td>
</tr>
<tr>
<td>HAVING</td>
<td><a href="https://docs.mongodb.com/manual/reference/operator/aggregation/match/" target="_blank" rel="noopener">$match</a></td>
</tr>
<tr>
<td>ORDER BY</td>
<td><a href="https://docs.mongodb.com/manual/reference/operator/aggregation/sort/" target="_blank" rel="noopener">$sort</a></td>
</tr>
</tbody>
</table>
</div>
<p>Now let&#8217;s look at few examples how to translate traditional SQL  Queries to JSON Query for SSIS MongoDB Source. We will use sample data we inserted in previous section.</p>
<h3>Creating Sample Data for MongoDB Query Examples</h3>
<p>For this exercise to write sample queries using below data. So let&#8217;s first create a collection called Order and insert following records using your favourite MongoDB client tool.</p><pre class="crayon-plain-tag">db.Orders.insert(
  {
    "OrderId" : 1000,
    "CustomerId" : "CUS001",
    "OrderTotal" : 2000.50,
    "Quantity" : 20,
    "OrderDate" : ISODate("2010-01-01"),
    "Country" : "USA",
    "Items" : [ {ItemId:10, UnitPrice: 100.00,Quantity: 10}, {ItemId:11, UnitPrice: 200.10,Quantity: 5}],
    "PaymentInfo" : { 
      "Method" : "Card",
      "Currency" : "USD" 
    }
  }
)

db.Orders.insert(
  {
    "OrderId" : 1001,
    "CustomerId" : "CUS001",
    "OrderTotal" : 1000.00,
    "Quantity" : 10,
    "OrderDate" : ISODate("2011-01-02"),
    "Country" : "USA",
    "Items" : [ {ItemId:10, UnitPrice: 100.00,Quantity: 10}],
    "PaymentInfo" : { 
      "Method" : "Card",
      "Currency" : "USD" 
    }
  }
)

db.Orders.insert(
  {
    "OrderId" : 1002,
    "CustomerId" : "CUS002",
    "OrderTotal" : 1000.00,
    "Quantity" : 5,
    "OrderDate" : ISODate("2012-01-01"),
    "Country" : "USA",
    "Items" : [ {ItemId:13, UnitPrice: 200.00,Quantity: 5}],
    "PaymentInfo" : { 
      "Method" : "Bank",
      "Currency" : "USD" 
    }
  }
)

db.Orders.insert(
  {
    "OrderId" : 1003,
    "CustomerId" : "CUS003",
    "OrderTotal" : 59000.00,
    "Quantity" : 10,
    "OrderDate" : ISODate("2005-01-02"),
    "Country" : "India",
    "Items" : [ {ItemId:14, UnitPrice: 5900.00,Quantity: 10}],
    "PaymentInfo" : { 
      "Method" : "Check",
      "Currency" : "INR" 
    }
  }
)</pre><p>
Here is how it would look like (We used <a href="https://robomongo.org/download" target="_blank" rel="noopener"><strong>RoboMongo</strong></a> i.e. <strong>Robo 3T</strong>) but you can use mongo.exe command line to issue above commands.</p>
<div id="attachment_2661" style="width: 1110px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2016/08/ssis-mongodb-aggregation-queries-group-by-sql-pipeline-stages.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-2661" class="size-full wp-image-2661" src="https://zappysys.com/blog/wp-content/uploads/2016/08/ssis-mongodb-aggregation-queries-group-by-sql-pipeline-stages.png" alt="Inserting Example data for MongoDB Aggregation Queries (RoboMongo / Robo 3T)" width="1100" height="677" srcset="https://zappysys.com/blog/wp-content/uploads/2016/08/ssis-mongodb-aggregation-queries-group-by-sql-pipeline-stages.png 1100w, https://zappysys.com/blog/wp-content/uploads/2016/08/ssis-mongodb-aggregation-queries-group-by-sql-pipeline-stages-300x185.png 300w, https://zappysys.com/blog/wp-content/uploads/2016/08/ssis-mongodb-aggregation-queries-group-by-sql-pipeline-stages-768x473.png 768w, https://zappysys.com/blog/wp-content/uploads/2016/08/ssis-mongodb-aggregation-queries-group-by-sql-pipeline-stages-1024x630.png 1024w" sizes="(max-width: 1100px) 100vw, 1100px" /></a><p id="caption-attachment-2661" class="wp-caption-text">Inserting Example data for MongoDB Aggregation Queries (RoboMongo / Robo 3T)</p></div>
<h3>Example 1 &#8211; MongoDB Aggregation Query with COUNT(*) &#8211; $group, $project</h3>
<p>Here is how to write COUNT(*) query in MongoDB. Below query will find order count by country. Each query must output _id field and you can refer Document column using $ prefix (i.e. &#8220;<strong>$Country</strong>&#8221; or for nested object use dot separator &#8220;<strong>$PaymentInfo.Method</strong>&#8221; ) . To output _id column with different name we have used Country: &#8220;$_id&#8221;. Because we including copy of _id we can remove _id column by doing  <strong>_id: 0.</strong>  To include column in output use <strong>YourColumanName: 1</strong> in $project stage.</p>
<p><strong>SQL Query:</strong></p><pre class="crayon-plain-tag">SELECT Country,Count(*) as OrderCount 
FROM Orders
GROUP BY Country</pre><p>
<strong>Mongo Shell Query:</strong></p><pre class="crayon-plain-tag">db.Orders.aggregate(
 [
   {$group : {_id : "$Country",OrderCount: { $sum: 1 }}} 
  ,{$project : {Country: "$_id", _id: 0, OrderCount: 1 }}
 ]
)</pre><p>
<strong>SSIS MongoDB Source Query:</strong></p><pre class="crayon-plain-tag">{Table: Orders,Method: aggregate} 
{ pipeline: 
   [
    {$group : {_id : "$Country",OrderCount: { $sum: 1 }}} 
   ,{$project : {Country: "$_id", _id: 0, OrderCount: 1 }}
  ]
}</pre><p>
<h3>Example 2 &#8211; MongoDB Aggregation Query with WHERE and ORDER BY- $match, $group, $project, $sort</h3>
<p>Here is how to write COUNT(*) query in MongoDB. Below query will find order count by country.</p>
<p><strong>SQL Query:</strong></p><pre class="crayon-plain-tag">SELECT Country,Count(*) as OrderCount 
WHERE Quantity &gt; 1
FROM Orders
GROUP BY Country
ORDER BY Country</pre><p>
<strong>Mongo Shell Query:</strong></p><pre class="crayon-plain-tag">db.Orders.aggregate(
 [
   {$match : {Quantity : { $gt: 1 }}} 
  ,{$group : {_id : "$Country",OrderCount: { $sum: 1 }}} 
  ,{$project : {Country: "$_id", _id: 0, OrderCount: 1 }}
  ,{$sort : {Country: 1}}
 ]
)</pre><p>
<strong>SSIS MongoDB Source Query:</strong></p><pre class="crayon-plain-tag">{Table: Orders,Method: aggregate} 
{ pipeline: 
   [
     {$match : {Quantity : { $gt: 1 }}} 
    ,{$group : {_id : "$Country",OrderCount: { $sum: 1 }}} 
    ,{$project : {Country: "$_id", _id: 0, OrderCount: 1 }} ,{$sort : {Country: 1}}  
   ]
}</pre><p>
<h3>Example 3 &#8211; MongoDB Aggregation Query with WHERE and HAVING Clause &#8211; $match, $group</h3>
<p>Here is an example of WHERE and HAVING clause. They both use $match stage but their orders are different. WHERE condition is applied before GROUP BY (i.e. $group) and HAVING condition is applied after GROUP BY.</p>
<p><strong>SQL Query:</strong></p><pre class="crayon-plain-tag">SELECT Country,Count(*) as OrderCount
FROM Orders 
WHERE Quantity &gt; 1
GROUP BY Country
HAVING Count(*) &gt; 0</pre><p>
<strong>Mongo Shell Query:</strong></p><pre class="crayon-plain-tag">db.Orders.aggregate(
 [ 
   {$match : {Quantity: { $gt: 1 }}}
  ,{$group : {_id : "$Country",OrderCount: { $sum: 1 }}} 
  ,{$match : {OrderCount: { $gte: 1 }}} 
  ,{$project : {Country: "$_id", _id: 0, OrderCount: 1 }}
 ]
)</pre><p>
<strong>SSIS MongoDB Source Query:</strong></p><pre class="crayon-plain-tag">{Table: Orders,Method: aggregate} 
{ pipeline: 
   [
      {
        $group : {_id : "$Country",OrderCount: { $sum: 1 }}
      }      
   ]
}</pre><p>
<h3>Example 4 &#8211; MongoDB Aggregation Query with $unwind (Flatten nested Array)</h3>
<p>Now lets look at an example of <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/" target="_blank" rel="noopener">$unwind operator</a>. $unwind can be used to perform operations on nested array. Common things would be flatten the hierarchy and then apply group by operation. Lets find out Average Quantity of Items By Order Number</p>
<p><strong>SQL Query:</strong></p><pre class="crayon-plain-tag">SELECT Orders.OrderId as OrderNumber,Avg(Items.Quantity) as AvgItemQty
FROM Orders 
JOIN Items ON Orders.OrderId = Items.OrderId
GROUP BY Orders.OrderId</pre><p>
<strong>Mongo Shell Query:</strong></p><pre class="crayon-plain-tag">db.Orders.aggregate(
 [ 
   {$unwind : "$Items"}
  ,{$group : {_id : "$OrderId",AvgItemQty: { $avg: "$Items.Quantity" }}} 
  ,{$project : {OrderNumber: "$_id", _id: 0, AvgItemQty: 1 }}
 ]
)</pre><p>
<strong>SSIS MongoDB Source Query:</strong></p><pre class="crayon-plain-tag">{Table: Orders,Method: aggregate} 
{ pipeline: 
  [ 
    {$unwind : "$Items"}
   ,{$group : {_id : "$OrderId",AvgItemQty: { $avg: "$Items.Quantity" }}} 
   ,{$project : {OrderNumber: "$_id", _id: 0, AvgItemQty: 1 }}
  ]
)</pre><p>
<h2></h2>
<h2>MongoDB Query with Dynamic Value / ISO DateTime</h2>
<p>There will be a time when you have to supply Dynamic Value from Variable or supply Dynamic Date time inside your query. Dates are little different than other data types. <a href="https://zappysys.com/blog/how-to-query-mongodb-by-date-or-isodate/" target="_blank" rel="noopener">Check this article</a> to learn more about passing dates in MongoDB Query.</p>
<p>For Dynamic Date use SSIS Variables <a href="https://zappysys.com/onlinehelp/ssis-powerpack/scr/ssis-format-specifiers.htm" target="_blank" rel="noopener">Format Specifiers</a></p>
<h3><strong>Example of DateTime query (Static Value)</strong></h3>
<pre class="crayon-plain-tag">{Table: Orders,Method: aggregate} 
{ pipeline: 
   [
     {$match : {OrderDate : { $gt: new ISODate("2010-01-01") }}} 
    ,{$group : {_id : "$Country",OrderCount: { $sum: 1 }}} 
    ,{$project : {Country: "$_id", _id: 0, OrderCount: 1 }} ,{$sort : {Country: 1}}  
   ]
}</pre>
<h3><strong>Example of using Dynamic Value from Variable</strong></h3>
<p>To pass date from SSIS Variable you can use <a href="https://zappysys.com/onlinehelp/ssis-powerpack/scr/ssis-format-specifiers.htm" target="_blank" rel="noopener">Format Specifiers</a>. (e.g. <strong>yyyy-MM-dd</strong>  or for full ISO date <strong>yyyy-MM-ddTHH:mm:ssZ</strong> )</p><pre class="crayon-plain-tag">{Table: Orders,Method: aggregate} 
{ pipeline: 
   [
     {$match : {OrderDate : { $gt: new ISODate("{{User::varOrderDate,yyyy-MM-dd}}") }}} 
    ,{$group : {_id : "$Country",OrderCount: { $sum: 1 }}} 
    ,{$project : {Country: "$_id", _id: 0, OrderCount: 1 }} ,{$sort : {Country: 1}}  
   ]
}</pre><p>
<h3></h3>
<h2>Conclusion</h2>
<p>MongoDB is one of the most popular NoSQL / Document Storage Engine. <a href="https://zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">SSIS PowerPack</a> make super easy and efficient to read/write data in MongoDB without any coding effort. <a href="https://zappysys.com/products/ssis-powerpack/download/" target="_blank" rel="noopener">Download SSIS PowerPack</a> to try out MongoDB features along with 70+ other components .</p>
<p><strong>Search terms:</strong><br />
mongodb group by count<br />
mongodb group by multiple fields<br />
mongodb group by date<br />
mongodb group example<br />
mongodb group sort<br />
mongodb group by month<br />
mongodb group by having<br />
mongodb group distinct<br />
mongodb group by sum<br />
mongodb aggregate<br />
mongodb aggregate sort<br />
mongodb aggregate unwind</p>
<p>&nbsp;</p>
<p>The post <a href="https://zappysys.com/blog/aggregate-mongodb-data-using-group-by-query-in-ssis/">How to write MongoDB Aggregation Queries in SSIS (Group By)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Insert Multiple Documents into MongoDB using SSIS</title>
		<link>https://zappysys.com/blog/insert-multiple-documents-mongodb-using-ssis/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Tue, 28 Jun 2016 00:55:05 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB ExecuteSQL]]></category>
		<category><![CDATA[BSON]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[SSIS MongoDB ExecuteSQL Task]]></category>
		<category><![CDATA[SSIS PowerPack]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=634</guid>

					<description><![CDATA[<p>Introduction In this post you will learn how to use MongoDB ExecuteSQL Task for SSIS to insert multiple documents into MongoDB collection using SSIS. This task can be used to perform any DDL or DML operations for MongoDB natively inside SSIS without using any command line utilities. It gives you flexibility and security of SSIS. [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/insert-multiple-documents-mongodb-using-ssis/">How to Insert Multiple Documents into MongoDB using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><img loading="lazy" decoding="async" class="size-full wp-image-2115 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png" alt="" width="88" height="88" />In this post you will learn how to use <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/" target="_blank" rel="noopener">MongoDB ExecuteSQL Task for SSIS</a> to <em>insert multiple documents into MongoDB collection</em> using SSIS. This task can be used to perform any DDL or DML operations for MongoDB natively inside SSIS without using any command line utilities. It gives you flexibility and security of SSIS.</p>
<p>&nbsp;</p>
<h2>Step-By-Step &#8211; Insert Multiple Documents into MongoDB Collection using SSIS</h2>
<p>Lets look at how to insert multiple MongoDB documents into</p>
<ol>
<li>Download SSIS PowerPack from here</li>
<li>Create new SSIS Package</li>
<li>Drag ZS MongoDB ExecuteSQL Task from SSIS Toolbox</li>
<li>Double click task to configure</li>
<li>Create new MongoDB connection by clicking on [New] button next to connection dropdown</li>
<li>Click OK to close connection UI</li>
<li>Now you can enter following Command in MongoDB ExecuteSQL Task to insert multiple documents into MongoDB. If you want to pass json stored inside SSIS variable then use variable placeholders (e.g. {{User::varMyJson}}  ) anywhere inside below command.<br />
<pre class="crayon-plain-tag">{
 scope: 'database',
 db: 'DemoDB',
 command: 'eval',
 args: { code: 'db.MyCollection.insert( [ {ID:1,Name:"AAA"}, {ID:2,Name:"BBB"} ] )' } 
}</pre>
</li>
</ol>
<div id="attachment_686" style="width: 814px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/06/ssis-insert-multiple-documents-in-mongodb-collection-json.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-686" class="size-full wp-image-686" src="//zappysys.com/blog/wp-content/uploads/2016/06/ssis-insert-multiple-documents-in-mongodb-collection-json.png" alt="Insert multiple documents in MongoDB Collection (JSON or BSON format)" width="804" height="567" srcset="https://zappysys.com/blog/wp-content/uploads/2016/06/ssis-insert-multiple-documents-in-mongodb-collection-json.png 804w, https://zappysys.com/blog/wp-content/uploads/2016/06/ssis-insert-multiple-documents-in-mongodb-collection-json-300x212.png 300w" sizes="(max-width: 804px) 100vw, 804px" /></a><p id="caption-attachment-686" class="wp-caption-text">Insert multiple documents in MongoDB Collection (JSON or BSON format)</p></div>
<h2>Conclusion</h2>
<p>Using <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/" target="_blank" rel="noopener">MongoDB ExecuteSQL Task for SSIS</a> you can execute ad-hoc MongoDB Shell commands without installing any command line tools. This is totally native SSIS approaching. You can Try <a href="https://zappysys.com/products/ssis-powerpack/">SSIS PowerPack for FREE</a> to find out many more MongoDB features not discussed in this article.</p>
<p>The post <a href="https://zappysys.com/blog/insert-multiple-documents-mongodb-using-ssis/">How to Insert Multiple Documents into MongoDB using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
