Introduction
In this post you will learn how to read MongoDB data from Array. We recently introduced new JSON Path expression feature in SSIS MongoDB Source Connector to extract nested information from MongoDB documents.
Read documents from Array in MongoDB
By default SSIS MongoDB Source Connector doesn’t support extracting data using JSON Path expression. So if you want to read nested data from sub-document or array then you have enable that option.
Consider following sample Document stored in MongoDB. Lets say you want to extract all orders for each customer.
For that you have enter $.Orders[*] in the JSON Path expression as below screenshots. Notice it also brings parent columns of each Orders (By default parent columns prefixed with P_ ).
To exclude parent columns from your resultset got to Advanced JSON Filter Options tab -> Uncheck “Include Parent Columns” option.
Sample MongoDB Document
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
{ "_id" : ObjectId("56a2ae6369e0f137a449f58b"), "CustomerID" : "ALFKI", "CompanyName" : "Alfreds Futterkiste", "ContactName" : "Maria Anders", "ContactTitle" : "Sales Representative", "LocationInfo" : { "City" : "Berlin", "Address" : "Obere Str. 57", "Region" : null, "PostalCode" : "12209", "Country" : "Germany" }, "Phone" : "030-0074321", "Fax" : "030-0076545", "OrdersIDList" : [ 10643, 10692, 10702 ], "Orders" : [ { "OrderID" : 10643, "EmployeeID" : null, "OrderDate" : "1997-08-25 00:00:00" }, { "OrderID" : 10692, "EmployeeID" : 4, "OrderDate" : "1997-10-03 00:00:00" }, { "OrderID" : 10702, "EmployeeID" : 4, "OrderDate" : "1997-10-13 00:00:00" } ] } |
Server side Filtering using MongoDB Query
JSON Path filtering happens on client side so first your selected set of documents fetched from MongoDB server and then transformation of happens on client side based on JSON Path you specified (de-normalization).
Below screenshots shows how to use MongoDB SQL Query Language (Read more here) to filter data on server side and then apply JSON Path expression to extract sub-documents or array items from MongoDB documents.