Forum Discussion
bojanvelevski
4 years agoValued Contributor
Hi @KTsnap,
Don’t know what you mean by “JSON” output? If you are referring to the Array value of “controllingFieldValue”, than just remove the square brackets from your expression
- KTsnap4 years agoNew Contributor III
Hi Bojan,
IN this way ,[ "Value" : { { "controllingFieldValue": [ "A" ], "valueName": "1" }, { "controllingFieldValue": [ "B" ], "valueName": "2" }, { "controllingFieldValue": [ "C" ], "valueName": "3" }, { "controllingFieldValue": [ "D" ], "valueName": "4" } } ]
- bojanvelevski4 years agoValued Contributor
This is not a valid JSON. The value of the “Value” object can either be a string,number,boolean, array , or object with key value pairs, but not multiple object literals. You can group all of the documents in one array ($group) , and use the following expression:
$group.map(x=>{"controllingFieldValue":[x.parents],"valueName":x.value})
And map the target path as Value, than you’ll have all of the objects but in an array.
- KTsnap4 years agoNew Contributor III
This helped… Thank you 🙂