xxxxxxxxxx
# if you have dynamic keys that you need to match on
# use $objectToArray to be able to work with them easier
{
$addFields: {
keyValuePairs: { $objectToArray: "$myObjectWithDynamicKeys" },
}
},{
# now you can use filter and search it like any other array now that you know the keys
$addFields: {
myMatchedObject: {
$filter: {
input: "$keyValuePairs",
as: "keyValue",
cond: { $eq: ["$$keyValue.k", "$myPropertyOrValue"] },
}
}
}
}