<?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>SSIS MongoDB Destination Archives | ZappySys Blog</title>
	<atom:link href="https://zappysys.com/blog/category/ssis/components/ssis-mongodb-destination/feed/" rel="self" type="application/rss+xml" />
	<link>https://zappysys.com/blog/category/ssis/components/ssis-mongodb-destination/</link>
	<description>SSIS / ODBC Drivers / API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more</description>
	<lastBuildDate>Fri, 27 Sep 2019 14:50:53 +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>SSIS MongoDB Destination Archives | ZappySys Blog</title>
	<link>https://zappysys.com/blog/category/ssis/components/ssis-mongodb-destination/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<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 fetchpriority="high" 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 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 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>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>SSIS &#8211; Loading data into MongoDB (Upsert, Delete, Update)</title>
		<link>https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Fri, 26 Feb 2016 22:03:21 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB Destination]]></category>
		<category><![CDATA[export json task]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[ssis connectors]]></category>
		<category><![CDATA[SSIS Dummy Data Source]]></category>
		<category><![CDATA[SSIS Export JSON Task]]></category>
		<category><![CDATA[SSIS JSON Generator Transform]]></category>
		<category><![CDATA[SSIS MongoDB ExecuteSQL Task]]></category>
		<category><![CDATA[SSIS MongoDB Source]]></category>
		<category><![CDATA[ssis tasks]]></category>
		<category><![CDATA[upsert]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=374</guid>

					<description><![CDATA[<p>Introduction MongoDB is one of the most poplar NoSQL database out there. In this article you will learn how to use ZappySys MongoDB Destination Connector to perform various bulk operations on MongoDB such as Insert, Update, Delete and Upsert. If you wish to learn how to Update MongoDB Array items then check this blog post instread. [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/">SSIS &#8211; Loading data into MongoDB (Upsert, Delete, Update)</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" />MongoDB is one of the most poplar <strong>NoSQL database</strong> out there. In this article you will learn how to use <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/">ZappySys MongoDB Destination Connector</a> to perform various bulk operations on MongoDB such as Insert, Update, Delete and Upsert. If you wish to learn <a href="//zappysys.com/blog/update-mongodb-array-items-using-ssis/" target="_blank" rel="noopener">how to Update MongoDB Array items then check this blog post instread</a>.</p>
<p>&nbsp;</p>
<h2>MongoDB data read/write Example SSIS Package</h2>
<p>Before we talk more about loading data into MongoDB lets look at screenshot and steps involved in our sample package for this tutorial. Below sample SSIS package uses 4 <strong>Custom SSIS Tasks</strong></p>
<ol>
<li><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/">SSIS MongoDB Source Connector</a> (Used to read data from MongoDB Collection)</li>
<li><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/">SSIS MongoDB Destination Connector</a> (Used to write data into MongoDB Collection also you can do other bulk operations such as MongoDB update, MongoDB upsert and MongoDB delete)</li>
<li><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/">SSIS MongoDB ExecuteSQL Task</a> (Used to call any MongoDB Shell commands including MongoDB DDL or DML type operations such as CREATE/DROP, Insert, Update, Delete, Read, you can also call server side JavaScript)</li>
<li><a href="//zappysys.com/products/ssis-powerpack/dummy-data-source-free/">Dummy Data Source</a> (Used to generate sample JSON Documents which can be loaded in MongoDB)</li>
</ol>
<h2>MongoDB Examples</h2>
<p>Here is the list of various MongoDB examples included in attached sample package (see at the end for download links)</p>
<ul>
<li>MongoDB example &#8211; How to <em>read data from MongoDB</em> collection using SQL query language</li>
<li>MongoDB example &#8211; How to <em>load raw JSON document</em> into MongoDB Collection (<strong>Bulk Insert with Reload</strong>)</li>
<li>MongoDB example &#8211; How to do <em>MongoDB Upsert</em> (<strong>Bulk Update</strong> or Insert) for specific fields or entire document</li>
<li>MongoDB example &#8211; How to perform MongoDB Delete ( <strong>Bulk Delete</strong> based on Matching Rows)</li>
<li>MongoDB example &#8211; How to <strong>create new MongoDB collection</strong> (Only if not exist &#8211; Use safe option)</li>
<li>MongoDB example &#8211; How to fetch MongoDB collection <strong>record count</strong> and save to SSIS variable</li>
<li>MongoDB example &#8211; How to fetch MongoDB <strong>collection size</strong> and save to SSIS variable</li>
<li>MongoDB example &#8211; How to <strong>get collection names</strong> and loop through them using ForEach Loop Task</li>
<li>MongoDB example &#8211; How to <strong>save query output</strong> into Recordset variable and loop though records using ForEach Loop Task</li>
</ul>
<h2>Video Tutorial &#8211; Update/Delete/Write/Bulk Load data into MongoDB from SQL Server/ORACLE</h2>
<p>In below video tutorial you will see how easy it is to load data into MongoDB from any Datasource such as SQL Server, Oracle, MySQL, Flatfile etc. You will also learn how to product nested JSON from multiple tables using <a href="//zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/" target="_blank" rel="noopener">JSON Generator Transform</a>. You can also use <a href="//zappysys.com/products/ssis-powerpack/ssis-json-file-source/" target="_blank" rel="noopener">JSON Source</a> with Output as Document Mode to load raw JSON data.</p>
<div><a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/"><img decoding="async" src="https://zappysys.com/blog/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FFkQjUahzMJQ%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></div>
<h2>Video Tutorial &#8211; Read data from MongoDB</h2>
<p>In the following video tutorial you will learn how to consume data from MongoDB Collection using <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">SSIS MongoDB Source Connector</a>. You will notice that it uses <strong>SQL query syntax</strong> rather than MongoDB specific native query syntax (JSON query). This makes it super easy to query data without any learning curve. Data stored in MongoDB is in JSON document format but Data coming out from <strong>MongoDB Source Connector</strong> is Flat table structure (It de-normalize nested nodes). You can also Query inner Hierarchy using <strong>JSON Path expression</strong> (e.g. query Orders from Customer Document using <strong>$.Customer.Orders[*]</strong> ) .</p>
<div><a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/"><img decoding="async" src="https://zappysys.com/blog/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FksvCA8FxOzI%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></div>
<div id="attachment_388" style="width: 362px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-loading-data-into-mongodb-read-from-mongodb-upsert-delete-insert-example.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-388" class="size-full wp-image-388" src="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-loading-data-into-mongodb-read-from-mongodb-upsert-delete-insert-example.png" alt="SSIS Example - Loading data into MongoDB, Read from MongoDB, Upsert, Upsert, Delete Insert JSON Documents, Execute Shell Commands" width="352" height="482" srcset="https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-loading-data-into-mongodb-read-from-mongodb-upsert-delete-insert-example.png 352w, https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-loading-data-into-mongodb-read-from-mongodb-upsert-delete-insert-example-219x300.png 219w" sizes="(max-width: 352px) 100vw, 352px" /></a><p id="caption-attachment-388" class="wp-caption-text">SSIS Example &#8211; Loading data into MongoDB, Read from MongoDB, Upsert, Upsert, Delete Insert JSON Documents, Execute Shell Commands</p></div>
<h2>MongoDB Insert &#8211; Bulk Loading data into MongoDB</h2>
<p>Using MongoDB Destination Connector you can easily Insert JSON documents in Bulk. There are two input modes for inserting records into MongoDB.</p>
<h3>Simple Mode &#8211; Loading data in simple mode (array not allowed)</h3>
<p>In simple loading mode you can map source columns to target column in MongoDB destination. If you Insert data using this mode then you cant load complex documents with array.</p>
<h3>Document Mode &#8211; Loading JSON documents into MongoDB</h3>
<p>In this mode you can insert/update/delete documents by mapping inbuilt __DOCUMENT__ input column which appears on mapping tab (Target columns). When you perform Insert you have two options (Insert (i.e. Append) and Reload (Truncate + Insert). When you select Operation=Reload in that case Collection is first Truncated and then new records are loaded.</p>
<p>In JSON document load mode if you don&#8217;t supply _id column part of your input JSON then new _id is automatically generated by MongoDB for newly inserted document.</p>
<div id="attachment_392" style="width: 589px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-load-json-documents-into-mongodb-collection.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-392" class="size-full wp-image-392" src="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-load-json-documents-into-mongodb-collection.png" alt="Loading JSON Documents into MongoDB Collection (Map Raw Document Column)" width="579" height="669" srcset="https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-load-json-documents-into-mongodb-collection.png 579w, https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-load-json-documents-into-mongodb-collection-260x300.png 260w" sizes="(max-width: 579px) 100vw, 579px" /></a><p id="caption-attachment-392" class="wp-caption-text">Loading JSON Documents into MongoDB Collection (Map Raw Document Column)</p></div>
<h3>Loading JSON files into MongoDB</h3>
<p>Another scenario could be loading JSON files into MongoDB. You can load JSON Files into MongoDB two ways.</p>
<ul>
<li>Use Flat File Source with just one column with DT_NTEXT datatype (use this method when you each JSON documents in one line and they are separated by new line as below screenshot)</li>
<li>Use <a href="//zappysys.com/products/ssis-powerpack/ssis-json-file-source/">JSON Source Connector</a> with Output as Document option checked. You can map __DOCUMENT__ source column to Target MongoDB collection as below. Advantage of this method is you extract JSON from array too and specify many other advanced options.
<div id="attachment_393" style="width: 733px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-extract-raw-json-documents-from-json-file.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-393" class="size-full wp-image-393" src="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-extract-raw-json-documents-from-json-file.png" alt="SSIS Extract JSON Documents or Sub Documents from JSON file or JSON Array" width="723" height="605" srcset="https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-extract-raw-json-documents-from-json-file.png 723w, https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-extract-raw-json-documents-from-json-file-300x251.png 300w" sizes="(max-width: 723px) 100vw, 723px" /></a><p id="caption-attachment-393" class="wp-caption-text">SSIS Extract JSON Documents or Sub Documents from JSON file or JSON Array</p></div></li>
</ul>
<h2>Specifying LoadOptions</h2>
<p><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/">MongoDB Destination Connector</a> supports following <strong>LoadOptions</strong> property (see Component Properties Tab on UI) which controls how target data gets modified. <strong>LoadOptions</strong> property is ignored for <strong>Reload</strong> and <strong>Insert</strong> operations.</p>
<ul>
<li><strong>op</strong> : this option specify update operators (Valid for <strong>Update, Replace</strong> and <strong>Upsert</strong> operation (i.e. <strong>UpdateOrInsert</strong>) ).  See <a href="https://docs.mongodb.org/manual/reference/operator/update/" target="_blank" rel="noopener">this link</a> for more information on various Update operators available in MongoDB. Most common operators listed below. Refer official MongoDB <a href="https://docs.mongodb.org/manual/reference/operator/update/" target="_blank" rel="noopener">help</a> for more information.
<ul>
<li><strong>op=none</strong> : Replace entire document</li>
<li><strong>op=$set</strong>  : Update only those fields specified in mapping. If Specified mapping field not available in target then its added to target document.</li>
<li><strong>op=$push</strong> : Adds new item to destination array. See following examples (How to insert single or multiple documents into MongoDB Array by supplying JSON into  __DOCUMENT__ column<br />
<pre class="crayon-plain-tag">/* Insert single item into array - Construct input JSON as below */
{YourArrayField : 111 }

/* Insert multiple items into array - Construct document as below */
{YourArrayField : { $each: [ 111, 222, 333 ] } }

/* Insert multiple documents into array */
{YourArrayField : { $each: [ {OrderID:1, Total:20.00}, {OrderID:2, Total:12.00} ] } }</pre>
</li>
</ul>
</li>
<li><strong>multi</strong> : This option controls if you want to Update or Delete multiple records for matching condition for each upstream input record.  For example if you joining by Country and City columns for update and target system finds 5 records then by default they all will be updated if <strong>multi=true</strong> is set in <strong>LoadOptions</strong> property. If you don&#8217;t want to update multiple records</li>
</ul>
<h2>MongoDB Update</h2>
<p>MongoDB Destination Connector supports Batch Update and Batch Upsert Operations. There are few things to remember how Update operation works with MongoDB Destination Connector.</p>
<ul>
<li>To perform Update operation you have to specify Join Criteria for record lookup on target (see <strong>ColumnsForLookup</strong> property).</li>
<li>Specify JOIN columns in <strong>ColumnsForLookup</strong> property. Use comma to specify multiple columns (e.g. CustomerID,OrderID). If you dont specify columns in this property then any columns mapped other than __DOCUMENT__ will be considered as JOIN column.</li>
<li>With MongoDB destination you can only specify simple Update condition by mapping JOIN input columns. Behind the scene it will construct search query for update. For example if you Map 3 input columns (__DOCUMENT__ , Country, State) and you specify <strong>LoadOptions :</strong> <strong>op=$set;multi=true</strong> then its similar as below SQL Statement.<br />
<pre class="crayon-plain-tag">UPDATE MyCollection
SET [properties specified in __DOCUMENT__]
WHERE Country=[input value] AND State=[input value]</pre>
</li>
<li>Join columns can be individually mapped or can be supplied as part of JSON document mapped to __DOCUMENT__ column.</li>
<li>If __DOCUMENT__ column is not mapped then you must specify at least one column name in ColumnsForLookup property to identify search column.</li>
<li>If __DOCUMENT__ column is mapped and column name is not specified in <strong>ColumnsForLookup</strong> property then you must map at least one more input column which can treated as JOIN column</li>
</ul>
<h2>Update specific fields  ($set operator)</h2>
<p>To update specific fields in target MongoDB collection you can map JOIN column(s) and then map fields you want to update or map __DOCUMENT__ if you suppling JSON document with fields you want to update.</p>
<p>See below screenshot where its updating Customers record with new coordinates  based on City and Country information.</p>
<div id="attachment_397" style="width: 758px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-update-json-document-specified-fields-set-operator.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-397" class="size-full wp-image-397" src="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-update-json-document-specified-fields-set-operator.png" alt="SSIS MongoDB Update Bulk - $set update operator - Update specific fields - Update single or multiple documents" width="748" height="527" srcset="https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-update-json-document-specified-fields-set-operator.png 748w, https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-update-json-document-specified-fields-set-operator-300x211.png 300w" sizes="(max-width: 748px) 100vw, 748px" /></a><p id="caption-attachment-397" class="wp-caption-text">SSIS MongoDB Update Bulk &#8211; $set update operator &#8211; Update specific fields &#8211; Update single or multiple documents</p></div>
<h3>Update single or multiple target records for single input row</h3>
<p>If you want to update all matching records in target then set <strong>LoadOptions</strong> property to <strong>op=$set,multi=true</strong><br />
If you want to update only one record per matching criteria in target then set <strong>LoadOptions</strong> property to <strong>op=$set,multi=false</strong></p>
<h3>Update entire document (i.e. Overwrite/Replace documents)</h3>
<p>If you like to replace entire target document then you can do two ways. Few things you have to change for MongoDB Destination.</p>
<p><strong>Approach#1 </strong></p>
<ol>
<li>Select <strong>Operation</strong>=Replace (Rather than Update or Upsert)</li>
<li>Specify Join column in <strong>ColumnsForLookup</strong></li>
<li>On the mapping tab Map __DOCUMENT__ (Assuming you have Raw JSON coming from Upstream)</li>
</ol>
<p><strong>Approach#2</strong></p>
<p>Another approach is use $set operator in LoadOptions property then it will only update specified fields in mappings. But if you want to overwrite entire document (Replace document) then set <strong>LoadOptions</strong> property to <strong>op=none,multi=true</strong> or <strong>op=none,multi=false</strong> (If you want to update one record for matching condition)</p>
<h3>Insert single item into MongoDB Array using $push operator</h3>
<p>If you want to insert new items into array then set <strong>LoadOptions</strong> property to <strong>op=$push,multi=true</strong> or <strong>op=$push,multi=false</strong> (If you want to update one record for matching condition). You have to map __DOCUMENT__ column on target mappings tab to supply item(s) or document(s) you want to insert into target array.</p><pre class="crayon-plain-tag">/* Insert single number or string into MongoDB array - Construct input JSON as below */
{YourArrayField : 111 }

/* Insert single document into MongoDB array - Construct input JSON as below */
{YourArrayField : {OrderID:1, Total:20.00} }</pre><p>
<h3>Insert multiple items into MongoDB Array using $push operator along with $each</h3>
<p>Inserting multiple items into array requires use of <strong>$each</strong> modifier as below. Use above instructions except input document (e.g. data passed to __DOCUMENT__ column) will look like below (see how $each used).</p><pre class="crayon-plain-tag">/* Insert multiple items into MongoDB array - Construct document as below */
{YourArrayField : { $each: [ 111, 222, 333 ] } }

/* Insert multiple documents into MongoDB array */
{YourArrayField : { $each: [ {OrderID:1, Total:20.00}, {OrderID:2, Total:12.00} ] } }</pre><p>
<h3>Other MongoDB Update Operators</h3>
<p>So far we have seen <strong>$set</strong> and <strong>$push</strong> update operators. To learn more about other operators see <a href="https://docs.mongodb.org/manual/reference/operator/update/" target="_blank" rel="noopener">this link</a></p>
<h2>MongoDB Update Array Items ($pull, $push, $addToSet)</h2>
<p>If you wish to update items found inside nested array of document then <a href="//zappysys.com/blog/update-mongodb-array-items-using-ssis/" target="_blank" rel="noopener">Check this full length article</a></p>
<h2>MongoDB Upsert &#8211; Bulk Update or Insert JSON documents</h2>
<p>If you wish to perform Bulk Upsert using MongoDB Destination connector then select Upsert Action from dropdown (Action=UpdateOrInsert). In Upset if document is not found for matching criteria then new document is inserted in MongoDB Collection. If document is found then Update operation occurs. To set specific fields use <strong>op=$set</strong> in LoadOptions   and if you wish to overwrite entire document then use <strong>$op=none</strong> in <strong>LoadOptions </strong></p>
<div id="attachment_400" style="width: 488px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-upsert-json-document-update-or-insert-bulk.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-400" class="size-full wp-image-400" src="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-upsert-json-document-update-or-insert-bulk.png" alt="SSIS MongoDB Upsert - Bulk Update or Insert JSON documents" width="478" height="605" srcset="https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-upsert-json-document-update-or-insert-bulk.png 478w, https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-upsert-json-document-update-or-insert-bulk-237x300.png 237w" sizes="(max-width: 478px) 100vw, 478px" /></a><p id="caption-attachment-400" class="wp-caption-text">SSIS MongoDB Upsert &#8211; Bulk Update or Insert JSON documents</p></div>
<h2>MongoDB Delete &#8211; Bulk delete MongoDB JSON documents</h2>
<p>To delete documents from collection you can set operation=Delete on Component properties page. For delete you can simply map _id column on target or just supply columns based on you want to search records you want to delete.</p>
<p>To delete maximum one record for each input row set <strong>LoadOptions</strong> property to <strong>op=none,multi=false</strong> or set <strong>op=none,multi=false</strong> if you want to delete more than one record for matching condition.</p>
<h2>MongoDB Collection Reload &#8211; Remove All (Truncate collection)</h2>
<p>To reload collection set operation to Reload on Component properties page. <strong>Reload</strong> operation first clears target collection and perform <strong>bulk Insert</strong> operation</p>
<h2>Generate JSON for MongoDB data load</h2>
<p>Now lets talk about different ways to produce simple or complex JSON using ZappySys components.  There are 3 ways you can produce JSON which can be loaded into MongoDB Collection. Following section will describe each approach and you can select which one best suited for you.</p>
<h3>Generate JSON &#8211; Using Export JSON Task</h3>
<p>Export JSON Task can export JSON to File or variable which you can consume via <a href="//zappysys.com/products/ssis-powerpack/ssis-json-file-source/">JSON Source Connector</a> (Check Output as Document option) and supply to MongoDB Destination Connector (map to __DOCUMEN__).</p>
<p>Check this link for more info :  <a href="//zappysys.com/blog/export-json-from-sql-server-using-ssis/" target="_blank" rel="noopener">Export Json from sql server using ssis</a></p>
<h3>Generate JSON &#8211; Using JSON Generator Transform</h3>
<p>JSON generator transform is useful when you want to Produce JSON inside pipeline from single or multiple input.</p>
<p>Check this link for more info :  <a href="https://zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/" target="_blank" rel="noopener">JSON generator Transform (Watch Video on this page)</a></p>
<div style="width: 600px" class="wp-caption alignnone"><img decoding="async" title="JSON Generator Transform - Generate JSON and Load into MongoDB" src="//zappysys.com/onlinehelp/ssis-powerpack/scr/images/json-generator-transform/ssis-json-generator-load-documents-mongodb.png" alt="JSON Generator Transform - Test JSON Path Settings" width="590" /><p class="wp-caption-text">JSON Generator Transform &#8211; Generate JSON documents and load into MongoDB</p></div>
<h3>Generate JSON &#8211; Using Dummy Data Source (Fake JSON for Testing)</h3>
<p>If you need to produce JSON for testing purpose then use <a href="//zappysys.com/products/ssis-powerpack/dummy-data-source-free/" target="_blank" rel="noopener">Dummy Data Source</a> (Select JsonDocuments Template from dropdown and click ok)</p>
<h2>Query/Read data from MongoDB</h2>
<p>Visit following links to learn more about reading data from MongoDB.</p>
<p><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/">SSIS MongoDB Source Homepage</a><br />
<a href="//zappysys.com/onlinehelp/ssis-powerpack/scr/mongodb-source.htm#A_QueryLanguage">MongoDB SQL Query Reference</a><br />
<a href="//zappysys.com/blog/read-mongodb-data-from-array-extract-nested-sub-documents/">MongoDB data extract &#8211; from nested sub documents and array</a></p>
<h2>Execute MongoDB Shell commands in SSIS (e.g. Create/Drop collection)</h2>
<p>MongoDB SOurce and Destination Connectors are great for read/write data. But what if you want to issue ad-hoc MongoDB shell command such as create collection/drop collection ? No worry.. <a href="//zappysys.com/products/ssis-powerpack/">SSIS PowerPack v2.0</a> released new Task called <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/">SSIS MongoDB ExecuteSQL Task</a> This task comes with many examples listed on the UI itself (Look for Examples dropdown menu on UI). You can use <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/">SSIS MongoDB ExecuteSQL Task</a> to perform many operations such as</p>
<ul>
<li>Create/Drop MongoDB collections</li>
<li>Get collection list as ADO.net recordset so you can loop through using ForEachLoop task</li>
<li>Call serverside JavaScript</li>
<li>Fetch data as ADO.net recordset and store in SSIS variable so you can loop using ForEachLoop task</li>
<li>Drop database</li>
<li>Call many shell commands</li>
</ul>
<h2>Download MongoDB Example Files used in this tutorial</h2>
<p>To test this package you first need to <a href="//zappysys.com/products/ssis-powerpack/">download SSIS PowerPack</a><br />
Once SSIS PowerPack installed you can download following SSIS sample project file(s).</p>
<p><a title="MongoDB Examples - Loading data into MongoDB - SSIS 2008" href="//zappysys.com/downloads/files/ssis/MongoDB_Load_Demo_2008.zip">Download sample files &#8211; SSIS 2008</a><br />
<a title="MongoDB Examples - Loading data into MongoDB - SSIS 2012" href="//zappysys.com/downloads/files/ssis/MongoDB_Load_Demo_2012.zip">Download sample files &#8211; SSIS 2012</a><br />
<a title="MongoDB Examples - Loading data into MongoDB - SSIS 2014" href="//zappysys.com/downloads/files/ssis/MongoDB_Load_Demo_2014.zip">Download sample files &#8211; SSIS 2014</a><br />
<a title="MongoDB Examples - Loading data into MongoDB - SSIS 2016" href="//zappysys.com/downloads/files/ssis/MongoDB_Load_Demo_2016.zip">Download sample files &#8211; SSIS 2016</a></p>
<h2>Conclusion</h2>
<p>MongoDB makes it super easy to store <strong>JSON documents</strong> and gives you whole new way of manipulating documents with ease of use. ZappySys SSIS Connectors and Tasks for MongoDB makes it possible to implement various data integration scenarios with MongoDB. <a href="//zappysys.com/products/ssis-powerpack/">Click here to Download SSIS PowerPack</a> and try it your self.</p>
<p><b>Keywords:</b><br />
<em>Loading data into MongoDB</em> | <em>mongodb upsert array</em> | <em>mongodb upsert example</em> | <em>mongodb insert or update</em> | <em>mongo insert or update</em> | <em>mongo upsert</em> | <em>mongo insert JSON</em> | <em>mongo upsert JSON | update data into MongoDB</em></p>
<p>The post <a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/">SSIS &#8211; Loading data into MongoDB (Upsert, Delete, Update)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
