Greeting to the comunity
I’m new in MongoDB query scripting and i’m facing the following situation.
I need to generate a CSV report with this structure
productCode productName branchCode branchName STORE_Gross_Commission SALESMAN_Gross_Commission
1001 PRODUCT NAME 1001 01 BRANCH 1 200.00 100.00
1001 PRODUCT NAME 1001 02 BRANCH 2 400.00 150.00
(the data is not real, i’ts just for example porpouse)
the document examp´le is as follows:
{
“productCode”: “1001”,
“productName”: “PRODUCT NAME 1001”,
“branchDistribution”: {
“branches”: [
{
“branchCode”: “01”,
“branchName”: “BRANCH 1”,
“commissionDistribution”: [
{
“participantTypeCode”: “001”,
“participantTypeName”: “STORE”,
“branchGrossCommission”: 200.00,
“branchNetCommission”: 150.00
},
{
“participantTypeCode”: “002”,
“participantTypeName”: “SALESMAN”,
“branchGrossCommission”: 100.00,
“branchNetCommission”: 50.00
}
]
}, {
“branchCode”: “02”,
“branchName”: “BRANCH 2”,
“commissionDistribution”: [
{
“participantTypeCode”: “001”,
“participantTypeName”: “STORE”,
“branchGrossCommission”: 400.00,
“branchNetCommission”: 200.00
},
{
“participantTypeCode”: “002”,
“participantTypeName”: “SALESMAN”,
“branchGrossCommission”: 300.00,
“branchNetCommission”: 150.00
}
]
}
]
}
}
how do i project the fields at the requested order without unwind the “commissionDistribution” nested document?.
Thanks for your collaboration.