I want to retrieve a value from an object with a dynamic key
[
{
"_id": 1,
"item": "sweatshirt",
"price": {
"INR": 45.99
},
"currency": 'INR'
}
]
db.collection.aggregate([
{
"$project": {
"pricenew": "$price.currency"
}
}
])
If I do price.INR
it will work fine but here I have currency dynamic, so I want something like price.currency
but here currency is coming like "INR" and it gives no data.
I really appreciate any help you can provide.