Debe comenzar con $objectToArray
para leer sus llaves dinámicamente. Luego puede $map
propiedades junto con $anyElementTrue
para detectar si hay algún campo anidado en thing
que contiene {"attribute1":"typeC"}
:
db.collection.aggregate([
{
$match: {
$expr: {
$anyElementTrue: {
$map: {
input: { $objectToArray: "$thing" },
in: { $eq: [ "$$this.v.attribute1", "typeC" ] }
}
}
}
}
}
])