I have a document like:
{
idx: {a: 1, b: 2, c: 3},
v: "a"
}
In an aggregation query, I'd like to add a field x to the doc by taking the value of v and using it to find the corresponding value in idx. The resulting doc would look like:
{
idx: {a: 1, b: 2, c: 3},
v: "a",
x: 1
}
I've tried things like $addFields: {x: "$idx.$a"} and $addFields: {x: "$idx[$a]"} but these are not working. I've scanned the list of pipeline operators but I don't see any that would help. Is this possible?