I have documents that look like this:
{
"_id": ObjectId("Some Value"),
"example_list" : [
{
"external_id" : ObjectId("Some Value1"),
"other" : "stuff"
},
{
"external_id" : ObjectId("Some Value2"),
"other" : "stuff"
},
{
"external_id" : ObjectId("Some Value3"),
"other" : "stuff"
}
]
}
I want to resolve the external_id (using a lookup) from a collection named example_collection for each object in the example_list so that the output resembles this:
{
"_id": ObjectId("Some Value"),
"example_list" : [
{
"external_id" : ObjectId("Some Value1"),
"other" : "stuff",
"external_data" : "data1 retrieved from lookup"
},
{
"external_id" : ObjectId("Some Value2"),
"other" : "stuff",
"external_data" : "data2 retrieved from lookup"
},
{
"external_id" : ObjectId("Some Value3"),
"other" : "stuff",
"external_data" : "data3 retrieved from lookup"
}
]
}
How can I accomplish this with an aggregate pipeline? I know how to do a lookup but not how to iterate over each object in the list and insert back into the object.