How can we get subfield from a collection using aggregation framework? Example,
Actual Document
{
"_id" : ObjectId("5c50589b4152f513f95809f2"),
"Address" : [
{
"AddressType" : "",
"Line1" : "555 N Duke Street",
"Line2" : "",
"Line3" : "",
"Area" : "AM-East Area",
"City" : "Lancaster",
"geoCode" : "Americas",
"District" : "",
"State" : "PA",
"Country" : "United States",
"PostalCode" : "17603",
"County" : ""
}
]
}
Expected Result
{
“Line1” : “555 N Duke Street”
}
I used below pipeline and got this result(array of the field value):
“Line1” : [
"555 N Duke Street "
]
Pipeline = [
{"$project" : { 'AddressLine1' : "$Address.Line1" }
},
{'$out' : "associationTransformed"
}
]