I have a mongo db aggregation query as follows:
db.collection.aggregate([ {"$addFields" :{ “placement” : { “$indexOfArray”: [ [“Closed Won”, “Commit”, “Qualified”, “Best Case”, “Pipeline”, “Needs Review”] , “$dlf.fcst_flag.Global#Global.state" ] }}},{”$sort" : { “placement” : 1 } }]);
where I am trying to sort based on indexOfArray.
I have a field “$dlf.fcst_flag.Global#Global.state” (highlighted in the query) where the value “Global#Global” can change when I run it in a loop. Assume that the value is stored in a variable called as node… So I want to take the value of the variable node.
Output: “$dlf.fcst_flag.Global#Global.state” → “$dlf.fcst_flag.node.state” . Instead of Global#Global, I need to get the value stored inside the variable node (where node can be either Global#Global or Global or Global! or anything else ).
How can I do that?