Read MongoDB data from array (extract nested sub documents)

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

 
Read MongoDB Data from array (extract nested sub documents)

Read MongoDB Data from array (extract nested sub documents)

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.

MongoDB Server Side Filter - Extract MongoDB Data from Array or nested sub-documents using SQL Query and JSON Path

MongoDB Server Side Filter – Extract MongoDB Data from Array or nested sub-documents using SQL Query and JSON Path

Posted in SSIS MongoDB Source and tagged , , , , .