I am attempting to use the Cosmos DB Data Migration tool to import from SQL Server 2014 to DocumentDB. The following is a sample SELECT statement:
SELECT
Sales.SalesOrderNumber AS [ID]
, Product.ProductName AS [Product.Name]
, Product.UnitPrice AS [Product.Price]
, Sales.SalesQuantity AS [Product.Quantity]
FROM ContosoRetailDW.dbo.FactOnlineSales AS Sales
JOIN ContosoRetailDW.dbo.DimProduct AS Product ON Product.ProductKey = Sales.ProductKey
WHERE Sales.SalesOrderNumber IN ('20070326214955','20070220416329')
ORDER BY Sales.SalesOrderNumber;
Here is a sample rowset from the above query. I have added Product. prefix to the DimProduct related columns, because I want Product to be a nested collection.
ID Product.Name Product.Price Product.Quantity
-------------------- ------------------------------------------------ --------------------- ----------------
20070207721039 MGS Hand Games women M400 Yellow 8.99 1
20070207721039 Adventure Works 26" 720p LCD HDTV M140 Silver 469.97 1
20070326214955 Adventure Works 20\" Analog CRT TV E45 Brown 200 1
20070326214955 Contoso 4G MP3 Player E400 Silver 59.99 1
Given the above sample rowset, here is an example of how I want my JSON document to be formatted:
[
{
"ID": "20070220416329",
"Products": [
{
"ProductName": "Contoso Mini Battery Charger Kit E320 Silver",
"Price": 24.99,
"Quantity": 1
},
{
"ProductName": "Adventure Works 26\" 720p LCD HDTV M140 Silver",
"Price": 469.97,
"Quantity": 1
}
]
},
{
"ID": "20070326214955",
"Products": [
{
"ProductName": "Adventure Works 20\" Analog CRT TV E45 Brown",
"Price": 200,
"Quantity": 1
},
{
"ProductName": "Contoso 4G MP3 Player E400 Silver",
"Price": 59.99,
"Quantity": 1
}
]
}
]
The problem is that each row is getting inserted a separate document, meaning (4) documents instead of (2), where Product is a nested document rather than a nested collection.
How do I accomplish what I'm trying to do?