Database

["_id":{"$oid":"68496c8a0bd223e0a0a52c26"},"products":{"locations":[{"location":"A","latDecDegree":"39","lngDecDegree":"20","sizes":[{"productId":"S_A_S","onSale":true,"locationId":"A","label":"S","size":"S","power":"3","price":"2","document":"/content/P_A_S.pdf"},{"productId":"S_A_M","onSale":true,"locationId":"A","label":"M","size":"M","power":"6","price":"3","document":"/content/P_A_M.pdf"},{"productId":"S_A_L","onSale":true,"locationId":"A","label":"L","size":"L","power":"9","price":"5","document":"/content/P_A_L.pdf"},{"productId":"A_S","onSale":false,"locationId":"A","label":"S","size":"S","power":"3","price":"2","document":"/content/P_A_S.pdf"},{"productId":"A_M","onSale":false,"locationId":"A","label":"M","size":"M","power":"6","price":"3","document":"/content/P_A_M.pdf"},{"productId":"A_L","onSale":false,"locationId":"A","label":"L","size":"L","power":"9","price":"5","document":"/content/P_A_L.pdf"},{"productId":"S_P_A_S","onSale":false,"locationId":"A","label":"S","size":"S","power":"3","price":"2","document":"/content/P_A_S.pdf"},{"productId":"S_P_A_M","onSale":false,"locationId":"A","label":"M","size":"M","power":"6","price":"3","document":"/content/P_A_M.pdf"},{"productId":"S_P_A_L","onSale":false,"locationId":"A","label":"L","size":"L","power":"9","price":"5","document":"/content/P_A_L.pdf"}]},{"location":"P","latDecDegree":"11","lngDecDegree":"25","sizes":[{"productId":"P_T_S","onSale":false,"locationId":"P","label":"S","size":"S","power":"3","price":"2","document":"/content/P_A_S.pdf"},{"productId":"P_T_M","onSale":false,"locationId":"P","label":"M","size":"M","power":"6","price":"3","document":"/content/P_A_M.pdf"},{"productId":"P_T_L","onSale":false,"locationId":"P","label":"L","size":"L","power":"9","price":"5","document":"/content/P_A_L.pdf"},{"productId":"S_P_P_T_S","onSale":false,"locationId":"P","label":"S","size":"S","power":"3","price":"2","document":"/content/P_A_S.pdf"},{"productId":"S_P_P_T_M","onSale":false,"locationId":"P","label":"M","size":"M","power":"6","price":"3","document":"/content/P_A_M.pdf"},{"productId":"S_P_P_T_L","onSale":false,"locationId":"P","label":"L","size":"L","power":"9","price":"5","document":"/content/P_A_L.pdf"}]}],"cost":"0"}}]

Query

db.collection.find({"$match":{"products.locations.sizes.productId":"A_S"},stages:incasecollectionisn'tnullreturnallproductsonSale:trueandafteritiflocationshavesizesemptyremoveobjectlocation})

Result