Hello, I’m trying to fetch from object the first key by pattern, then fetch this key in another property.
- first - retrieve from codesMap first match value X
- retrieve this value in items.X
If I project the dynamicField it contains the correct path to the value
{
$match: {
_id: "7646423017805410"
}
},
{
$addFields: {
dynamicField: {
$let: {
vars: {
matchingItemId: {
$reduce: {
input: {
$objectToArray: "$codesMap"
},
initialValue: [],
in: {
$cond: [
{ $regexFind: { input: "$$this.k", regex:"^KM510(\\§\\§.*)?$" } },
"$$this.v",
"$$value"
]
}
}
}
},
in:{ $concat: ["items.", "$$matchingItemId"] }
}
}
}
},
{$project: {
$getField: {field:"$dynamicField"}}
}
]
Does anyone knows why I'm getting error on getField?
Invalid $project :: caused by :: FieldPath field names may not start with '$'. Consider using $getField or $setField.
tried also without the concat and add input : $items but also didn't worked.
type or paste code here